Hi let´s say I have a folder with 4 documents on it, but 2 of them are duplicates like:
Automation.docx Automation (1).docx Automation (2).docx
New_Automation.docx
How could I manage to delete all duplicate files with any kind of number in parenthesis?
To begin with, you can use search pattern expression to pull these files into an array.
In this simple example, if your files have numbers they will end with a closing moon bracket “)” just before the “.docx” file identifier
string[] filesToDelete = Directory.GetFiles(myFolderPath, "*).docx");
For each file in filesToDelete
Call File Delete Activity and pass it the file variable
(From fi In New DirectoryInfo("C:\_RPA\_Demo").GetFiles()
Where Regex.IsMAtch(fi.Name,"\(\d+\)\.docx$", RegexOptions.IgnoreCase)
Select fi.FullName).toArray
ensure that following namespaces are imported:
optionally:
we can prefilter to a extension as well
modify the regex pattern also to catch typically abc (1) Copy.docx cases
It worked, I changed it so that it deletes every duplicate document with any type of extension, how could I add to delete the copy documents?
Ex:
MyFile.pdf
MyFile - copy.pdf