Copy files with conditions to folders

I have folders of files that have subdirectories (more than 10)…
And I only want files with name contains “TB” or “*.XLS” files to be move to the folder.

How do I do that?

HI @Uioptimusprimeolive

welcome to community!

Use for Each file in folder activity

Filter → “*.xls”

Use move activity

Look into the screenshot


To get file extension you can using :
System.IO.Path.GetExtension(yourFilePath) Or GetExtension(yourFilePath)

To Check is an string contain other string :

You can also try
1.Assign files=Directory.GetFiles(folderpath,pattern)
folderpath=folder path in which you want to search files as “c:/imporant files”
pattern=give pattern as “.xls”
2.Iterate files as foreach with type argument as string.

Hi @Uioptimusprimeolive ,

Could you try this?
Assign →

str_Folderpath = "Folder path"
Directory.GetFiles(str_FolderPath,"*.*").Where(Function(w) System.Text.RegularExpressions.Regex.IsMatch(w,"(TB)|(\.xls(?=$))")).ToArray()

Kind Regards,
Ashwin A.K

I did this but nothing happen

sorry I am new to this.

How should I apply the code into which tools?

I am coming from Alteryx and Power Automate background

Hi @Uioptimusprimeolive

Here is the workflow (176.7 KB)



Thanks for the prompt reply!

I tried playing around with your flow, and encounter some questions


Why cant I edit the <[CurrentFile.Extension.ToString.Equals(".xls")]> to <[CurrentFile.Extension.ToString.Contains(".xls")]>

It seems like it doesnt allow me to do so.

Hi @Uioptimusprimeolive

Equal → Exact output (Checks whether two variables are equivalent)

Contains → InExact word (The words contains in the variable)


I mean how do you type it into here

Try it in this way @Uioptimusprimeolive

After some tweaks, i can get the files i want and rename it!


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.