Copy Files started with Same Charachetrs into Separate folders


Anyone can help to share an approach on how to search my Computer all files which starts with same 8 Characters and put them in separate folders :
Example :



Those 2 first Files need to be copied to same folder as there 8 1st characters are the same , let’s say : Folder20220122, and the last 2, will be copied in another folder let say : Folder20220123

Thanks in advance

Hi @hsendel

first you have to create variable with DirectoryInfo type Ex : Folder

then you have to create a variable with Array of FileInfo type Ex: SpecificFiles

put the below syntax in Assign activity

Folder = new DirectoryInfo(“your source folder”)

SpecificFiles = Folder.GetFiles("*.xlsx").Where(function(file) file.Name.Contains("20220122")).OrderByDescending(function(d) d.LastWriteTimeUtc).ToArray

SpecificFiles holds all the excels which filename starts with 202200122

Pass the SpecificFiles in for each activity and

inside the for each use move file activity to move that file

look at the below xaml file for more reference

Sequence.xaml (6.6 KB)

Hope it solves your issue

update us whether you got your desired solution or not


1 Like

Thanks @Robinnavinraj_S , I will check and revert back to you.

1 Like

Thanks @Robinnavinraj_S , It’s Working as desired, I’m not sure if we can make it more smart :

1- We make input string as var ( depends on 8 characters , no need to put them inside formula, just check all similar files with same prefix and put them inside different folders)
2- We include sub-folder in source folder : “Folder = new DirectoryInfo(“your source folder”)”

Update → I find something similar, I will check that : Using UiPath to sort digital photos - Tutorial - YouTube

Hope is Clear :slight_smile:

HI @hsendel ,

You want to search in Sub folders as well ?


1 Like

Hi @Shikhar_Tandon , YES