cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Radhika1
Helper IV
Helper IV

Filtering files through 'Get files in folder ' action in PAD

currently I am working on files using power automate desktop, so I have the folder having 3000+ files(all pdfs) and out of it, I need to retrieve only 187 files (all pdfs) by filtering it by only the first 9 characters of the files (for ex: ABC-1234). the full file names is ABC-1234 v4.0.pdf. 

This first nine characters will be unique for each file. How can I give the filter option in the get files in folder action. Or is there any options available to retrieve the files by partial names ?

Please suggest me. Your help is much needed.

 

 image.png

 

I want to give it as in screenshot for 187 files in a single field. Looking forward for the solution. 

41 REPLIES 41
burque505
Helper V
Helper V

I can't figure out from the thread what the criteria would be to move each file to a specific destination folder.

Perhaps PowerShell might work better. I haven't tested any of this, but PowerShell regex page has some cmdlets that look like they might do just what you want.

 

You might try RoboCopy also, as it is a tool probably already on your Win10 machine and will take wildcards.

Here's a recursive example, you would of course need to modify the folders.

 

 

ROBOCOPY C:\sourceFolder1 C:\destinationFolder2 ABC*.pdf /E 
ROBOCOPY C:\sourceFolder2 C:\destinationFolder2 LVF*.pdf /E 

 

 

Simple RoboCopy flow with one command.

doscommand.png

command.png

This ran for me super fast even from the editor.

Seems like a loop would be useful here.

 

Edit: RoboCopy takes both * and ? as wildcards. A link to a docs page for it is here. 

I tested my flow above with this change

 

robocopy "C:\Users\MyUser\Documents\PADdocuments\foldertest" "C:\Users\MyUser\Documents\PADdocuments\foldertest2" DRV-????-*.pdf /E

 

and it worked fine. You could use additional wildcards and variables to narrow it down further.

robocopy %SourceFolder% %DestFolder% DRV-????-*.pdf /E

This works also.

 

Hi, Thanks for your suggestion, I did not try the robocopy, may be I can try that also.

However, I did renaming the necessary files through excel macros and retrieved the necessary files through PAD and moved to the specific folder, now again I want to rename it to the original name. So, when I run the excel macros, it asking for the folder to select and at a time I can select only one folder. There are altogether 25 folders and subfolders, 25 times I need to run the excel macros to rename the files present in the folders and subfolders. Is there any way to rename the files at a time for all the folders and subfolders?

Hi burque505, I tried robocopy, it is working super good, I regret I have not used it before.

Thank you so much, it is very simple and quick. 

Need one clarification, is it possible to give more than one file in the same command separated by a semicolon, I tried giving like that, it is copying only the first mentioned file. If any other solution for retrieving more than one file, please share it.

Refer to the screenshot.

 

Radhika1_2-1618060278501.png

 

 

 

 

 

Hi @Radhika1, you can use this syntax (no commas needed). Here I copy to C:\temp from the current directory.

Caveat: I haven't tried this with PAD yet (not at PAD machine) but it should work.

 

 

robocopy . C:\temp file1.pdf file2.pdf

 

 

To speed things up, use '/MT':

 

/MT[:n] 	Creates multi-threaded copies with n threads. n must be an integer between 1 and 128. The default value for n is 8. For better performance, redirect your output using /log option.

 

Regards,

burque505

 

p.s. robocopy docs page 

I tried with the variables, it is not working with me, I don't know why. First I created a input variable and then assigned the variables in the action but it is not working. May I know anything steps needs to follow inbetween.

 

Radhika1_1-1618070132103.png

 

burque505
Helper V
Helper V

Is it possible that %SourceFolder% and %FirstFolder% are reversed? Nothing would get copied if that were the case. (In your example %FirstFolder% needs to be the destination folder.

Another possibility - these switches:

/b 	Copies files in backup mode. Backup mode allows Robocopy to override file and folder permission settings (ACLs). This allows you to copy files you might otherwise not have access to, assuming it's being run under an account with sufficient privileges.
/zb 	Copies files in restartable mode. If file access is denied, switches to backup mode.

I tried reverse also, it is not working. If I provide the path instead of variable it is working. But for the variables, it is not copying the files. any solutions?

I'm stumped. This is working for me:

flow2.png

flow3.png

 

Are able to share a screenshot of how you are assigning your variables? That's the only other thing I can think of that might be at the root of the problem.

here is the screenshot

Radhika1_0-1618076119288.png

 

burque505
Helper V
Helper V

The only other thing I can think of to try is to add the variables using the little '{x}' instead of typing in %SourceFolder% and %FirstFolder%, and maybe that's what you did anyway.

 

EDIT: Removed edit. My mistake.

I got a solution, the variables should be inside a double quotes. Now, it is working.

robocopy "%Sourcedfoder%" "%destfolder%" 

Beautiful! 👍

Hi again,

 

I want to replace the old files that are existing with the new files in the folder. I am using robocopy to copy the files from source to destination, so it copies the new file but the old files still exists in the folder. The old file name has some version number and new file name will have a latest version number.

For ex:

ABC-1234-v.4.0 HTM - xxxxx x x x x xxxxxx.pdf will change to ABC-1234-v.5.0 HTM - xxxxx x x x x xxxxxx.pdf

 

So, now the existing file name should be replaced with the newer file name in the folder. Is there any option available in robocopy to replace the file names.

 

Your help is much appreciated!

burque505
Helper V
Helper V

Hi @Radhika1, I don't believe that option is among the many that robocopy has. Please take a look at this guide by Adam The Automator to robocopy. I would suggest perhaps a) copying the new files to a folder as you presently do, perhaps with the /mov option or another combination of options; b) also copying them to a temp folder;  c) deleting the files in the source folder; and d) copying the files in the temp folder back to the source folder.

Hi, 

Even I also thought so, deleting the files in the source folder and replacing the new files in the folder structure will work. Thanks for your reply.

hi,

I  need a help regarding the topic we discussed here. I need to delete the files which have the same pattern as

ABC-1234-v.4.0 HTM - xxxxx x x x x xxxxxx.pdf

 

I tried this in PAD:

Radhika1_1-1620198073539.png

 

As you see in the screenshot, it is taking the file which has a same pattern but if I use delete that 'Match', it says that File to delete not found. How to delete only the files which have the pattern like 

ABC-1234-v.4.0 HTM - xxxxx x x x x xxxxxx.pdf

 

Thanks,

Radhika

burque505
Helper V
Helper V

Here's a flow to get a list of files:

flow.PNG

The 'Get files in folder' activity:

files.PNG

Now you have a List of all files matching the pattern. You can loop through the list and delete them.

Here are files in my folder:

in folder.PNG

Now, a message displaying the three that match:

message.PNG

These are in the variable List called %Files%. Just loop through the list and delete.

The problem is I don't have the same letter and number for each file. Each file has different letters and numbers, they are unique.

burque505
Helper V
Helper V

You may be forced to use 'Parse text' so you can use regular expressions on the file names. That will not be fast, however. You could first use 'Get files in folder' for your list of files. Then loop through, parse for a regular expression to match your file pattern, then delete if it matches the regular expression.

 

However, if the letters and numbers are consistent as to number of letters/digits, hyphens, and spaces, you could try this (changing '.txt' to '.pdf', of course). The '*' in the version numbers ensures it will pick up things like "XZH-4239-v.27.292 QRZ [etc.]". You can of course experiment with different sequences of '?' and '*' until you can be virtually certain it will pick up all your use cases.

wild_cards.PNG

Hi, I have tried something like this and it is working

Radhika1_0-1620229516483.png

Thank you for the solution!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,107)