Copy files retroactive date

Hi guys !!
I’m having a problem, I have a BACKUP folder with 5,000 files, but I just want to copy it from 6 days ago, is there a solution?

@Luan_Carvalho_Da_Conceica

Welcome to our UiPath community

Try below expression.

List<String> requiredFiles = (from f in new DirectoryInfo("BackupFolderPath").GetFiles() where f.CreationTime >= Now.AddDays(-6) select f ).ToList()

The above expressions will give you last 6 days file. Then use For Each loop activity and inside use Copy File activity to copy files to destination directory.

Hi !
I still don’t understand, is there any possibility to assemble a simple example?

observation; I have standard studio ignore studioXle?

@Luan_Carvalho_Da_Conceica

I don’t have any workflow in ready for above scenario.

Try above expression and replace BackupFolderPath with actual folder path.

Copy files 6 days ago until today to different folder - is this requirement? Please clarify or brief your requirement…

Hi !

That’s right! copy the files from the last 6 days to a different folder.

Here you go with a xaml on this

Hope this would help you resolve this
copyfile.zip (2.4 KB)

I have commented out the copy file activity
Press on that activity and press ctrl+e so that it will get enabled

And in the expression mention your folder path

Cheers @Luan_Carvalho_Da_Conceica

1 Like

@Luan_Carvalho_Da_Conceica - If you would like to do it in a traditional way…

  1. For Each

    Directory.GetFiles(“YourFolderName”) and I am calling as EachFile instead of default Item

  2. IF

    New FileInfo(eachFile).LastWriteTime.Date >= Today.Date.AddDays(-6)
    

Then → Copy File Activity
Else → Nothing

LINQ Method…

StrArrFiles = Directory.GetFiles("YourFolderName").Where(Function(x) New FileInfo(x).LastWriteTime.Date >= Today.Date.AddDays(-6)).ToArray

Use StrArrFiles in the ForEach activity and inside use CopyFile activity…

OR write the LINQ code directly in the ForEach statement…

Hope this helps…

1 Like

it didn’t work, because I was copying everything that was in the folder, however, adding a formula from our friend @prasath17, it worked.
so thank you all for your help!

Thanks ! Your formula worked !!

Wondering how come
Because I included the same formula and I tried from my end as well
@Luan_Carvalho_Da_Conceica

Your > Directory.GetFiles(“C:\Users\palan\Documents\UiPath”).ToList().Where(Function(a) CDate(new System.IO.FileInfo(a).CreationTime)>Now.AddDays(- 6)).Toarray

replace your formula with that of your friend @prasath17

Directory.GetFiles(“YourFolderName”).Where(Function(x) New FileInfo(x).LastWriteTime.Date >= Today.Date.AddDays(-6)).ToArray

Yeah I have used CreationTime of the file and filtered -6 days ago file alone

Instead of this I suggested to keep your folderpath

And he has used Lastwritetime which is last edited time of the file and filtered -6 days ago file alone

Cheers @Luan_Carvalho_Da_Conceica