Hello guys, I need delete specifics itens of a folder but I need leave some itens:
Exp: Here I need delete all files and leave only files with name (Download_1,Download_2 and Download_3)
thx!
Hello guys, I need delete specifics itens of a folder but I need leave some itens:
Exp: Here I need delete all files and leave only files with name (Download_1,Download_2 and Download_3)
thx!
1.) Set a String (String array) variable FileArr
to System.Directory.GetFiles(FileDir)
, where FileDir
is a string variable containing the directory where the files are saved.
2.) Create a For Each activity to iterate over FileArr
. For further steps, I’ll refer to the individual item as MyFile
.
3.) Create an If activity with condition String.IsNullOrEmpty(System.Text.RegularExpressions.Regex.Match(MyFile, "download_\d+\.pdf").Value)
. In the Then block of the If condition, use a Delete File activity for MyFile
.
Hello @Anthony_Humphries.
If I have 5 folders with the same itens and I need delete this files to, what I need do?
Exmp: all folders have the same itens and I need enter in each one and delete files different of "“Downloads files”.
Folder 1 (Download_1,Download_2 and Download_3)
Folder 2 (Download_1,Download_2 and Download_3)
Folder 3 (Download_1,Download_2 and Download_3)
Folder 4 (Download_1,Download_2 and Download_3)
Folder 5 (Download_1,Download_2 and Download_3)
thx!
You can either create 5 loops, or you can create a dynamic loop where you iterate until an index variable is greater than 6. For example, if MyIx
is the index starting at 1, and the condition to exit the loop is MyIx > 5
, then you can set MyFolder
to String.Concat(FileDir, "\Folder ", MyIx.ToString)
. Then iterate over MyFolder
instead of FileDir
.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.