Hi,
I have list of files in Folder ,I need to check if the File name starts with ‘ABC’ and in the the middle if ‘Draft’ is there then need to consider only that files.
Kindly help with the Regex expression.
Below are the File name:
ABC123 - Draft 13.xlsx
ABC234 - Draft 14.xlsx
ABC567 - Draft 11.xlsx
lrtetala
(Lakshman Reddy)
July 2, 2024, 8:45am
2
Hi @yashashwini2322
ABC\d+\s+\-\s+Draft\s+\d+
System.Text.RegularExpressions.Regex.IsMatch(CurrentFile.Name.ToString,"ABC\d+\s+\-\s+Draft\s+\d+")
Regards,
Parvathy
(PS Parvathy)
July 2, 2024, 8:48am
3
Hi @yashashwini2322
filteredFiles = Directory.GetFiles("C:\Your\Folder\Path").Where(Function(f) Regex.IsMatch(Path.GetFileName(f), "^ABC.*Draft.*\.xlsx$")).ToArray()
Run a For Each loop for filteredFiles
For Each file in filteredFiles
Log Message -> file
End For Each
Hope it helps!!
Hello @yashashwini2322
try the following -
^(ABC|abc).Draft. .xlsx$
The above expression will check for the file names that start with “ABC” or “abc” which has “Draft” in the middle and has “.xlsx” file extension.
Thanks and Regards,
Ruchir Mahajan.
mkankatala
(Mahesh Kankatala)
July 2, 2024, 8:57am
6
Hi @yashashwini2322
Instead of using the Regular expressions, use the String Manipulations and use the below condition in If activity,
FileName.toString.Starswith("ABC") andalso FileName.toString.contains("Draft")
Hope it helps!!
@yashashwini2322 ,
Use this in assign activity to get only the files which are actionable. This will save your bot’s time to iterate unnecessary files.
filteredFiles = Directory.GetFiles("C:\Your\Folder\Path").Where(Function(myfile) Path.GetFileName(myfile).StartsWith("ABC") AndAlso Path.GetFileName(myfile).Contains("Draft"))).ToArray()
Regex will be a strict pattern here, better to go with string methods.
Thanks,
Ashok
system
(system)
Closed
July 20, 2024, 5:13am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.