Read files from dynamic folder with timestamp

I have folders named ABC_MMddyyyy_HHMM. For each day, there will be more than two folders with different time stamps. I want to copy files from this folder and move them to another location. The files in this folder have the same name and extension. For example, suppose I have two folders named ABC_01152024_1625 and ABC_01152024_1634. Each folder has two files, of which I wish to copy one and move it to another location. The file name in both folders is the same, for example, Filename.txt.
Also, when file is copied and move 2 different location, those file should have timestamp.

Please guide me! Thank you in advance.

Hi @harsh2

To get only directories for today, you can assign this expression to a array of strings

TodayFolders = System.IO.Directory.GetDirectories("path_to_root_directory", "ABC_"+DateTime.Now.ToString("MMddyyyy_")+"*", SearchOption.TopDirectoryOnly)

Then do something like this

Cheers

Loop through the folder either using for each folder activitiy or directory.getdirectories and put a condition like if foldername_loop_varibale contains datetime.now.tostring(“MMddyyyy”), then copy/move the files inside that folder to the destination and put a break. So whenever the first folder is identified bot moves the files and stops there.

Thank you so much ! Much appreciated.

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