We have a scenario involving a “For Each File in Folder” activity where some files have a .exe extension. We want to automatically delete all files with the .exe extension.
Additionally, we need a solution to identify and remove files of any extension that were created or modified within the last 15 minutes.
One small suggestion: before directly deleting the files, first use a Log Message activity to print CurrentFile.FullName. This will help you verify that the correct files are being picked before deletion.
follow the steps below, by this you are going to identify all the files which are havig the .exe extension or any other extension
Take assign activity
create a variable with the type array of string
pass that variable in Assign activity in To section
And in value section pass the below expression, at the place of .exe you can pass any other extensions that you want,
Directory.GetFiles(“C:\Users\YAregala\Downloads”,“*.exe”)
I need a small help. In my Downloads folder, we have approximately 300 files with different extensions. Our requirement is to delete only those files that were downloaded within the last 15 minutes, regardless of their extension.
However, as per the current approach, the process is looping through all files and taking around 3 minutes to delete a single file that meets the 15-minute condition.
Could you please suggest a more efficient way to handle this?
For 300 files, it should not take 3 minutes to delete one file. Instead of checking and deleting inside many activities, you can first filter the recent files and then delete only those.
You can do this with invoke code activity with in one line.
For that follow the below steps,
Take the **Invoke code **activity
Click on Edit code - and enter the below expression
Directory.GetFiles(downloadFolderPath,“*.xlsx”).Where(Function(f) File.GetCreationTime(f) >= Now.AddMinutes(-15) OrElse File.GetLastWriteTime(f) >= Now.AddMinutes(-15)).ToList.ForEach(Sub(f) File.Delete(f))
in above code downloadFolderPath is a argument that i used, click on edit argument and add this argument and your folder path.
You can handle both conditions inside the “For Each File in Folder” loop using an If condition. First, check the extension using “CurrentFile.Extension.Equals(”.exe")
and delete the file if true. For the second requirement, compare the file’s Created or LastWriteTime with “Now.AddMinutes(-15)”. If the file was created or modified within the last 15 minutes, delete it. This way you can automatically remove both .exe files and recently created/modified files in the same workflow