Hi All,
I want to delete all the old file from the folder except the latest file.How to delete all the all files from folder EXCEPT the LATEST file?
Regards,
Ritesh
Hi All,
I want to delete all the old file from the folder except the latest file.How to delete all the all files from folder EXCEPT the LATEST file?
Regards,
Ritesh
First, get all the file names from the specified folder into an array like this:
fileList = Directory.GetFiles("Your Folder Path")
Then, determine the latest file like this:
latestFile = fileList.OrderByDescending(Function(x) New FileInfo(x).LastWriteTime).FirstOrDefault()
Now, you can loop through each array element & check if the current file name is equal to the latestFile
, if not, you can use the Delete File activity to delete the current file.
Hope this helps,
Best Regards.
Try this
Assign activity:
Assign activity:
Assign activity:
For Each activity:
If activity:
Delete File activity:
- FilePath: item
Hope it helps!!
Regards,
You can do as below
Hope this helps
cheers
Hi @Anil_G ,
This is not working actually , its not giving the current index.equals(0) as True. rather delting all the files.
Could u please check this one?
Regards.,
Ritesh
Its done , index issue.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.