Hi there,
Input is
A_1_B.XLSX
B_0_C.XLSX
C_5_D.TXT
D_3_E.TXT
E_2_F.XLSX
I need to print the input in Ascending Order based on the Integer Value
OUTPUT:
B_0_C.XLSX
A_1_B.XLSX
E_2_F.XLSX
D_3_E.TXT
C_5_D.TXT
thanks in advance,
@ppr
@Yoichi
@ushu
@vishal.kp
@supermanPunch
@Anil_G
@rlgandu
regards .
@kmaddikatla
lrtetala
(Lakshman Reddy)
August 10, 2023, 6:48am
2
Hi @kmaddikatla
Please check on this thread
Here I’m trying to arrange text files in ascending order. can anyone help me
These are the file names.
A_2_B.TXT
B_1_c.Txt
C_3_D.xlsx
D_4_c.xlsx
E_5_e.txt
The output is:
B_1_c.Txt
A_2_b. Txt
C_3_D.xlsx
D_4_c.xlsx
E_5_e.txt
I hope it helps!!
Hi @kmaddikatla ,
I think you can get only numeric string then sort
Hello @ruteesh_raju , try this:
Use the “Directory.GetFiles” activity to get a list of all files in the specified folder.
Use the “Assign” activity to create a new List of String to store the filenames.
Use a For Each loop to iterate through each file path in the list of files.
Inside the For Each loop, use the “Path.GetFileName” method to extract the filename from the file path.
Use regular expressions to extract the numeric value from the filename.
Use the “Convert.ToInt32” method to convert …
Regards,
LNV
rlgandu
(Rajyalakshmi Gandu)
August 10, 2023, 6:54am
4
@kmaddikatla
Assign: folderPath = “C:\Path\To\Your\Folder”
Assign: filePaths = Directory.GetFiles(folderPath)
Assign: sortedFilePaths = filePaths.OrderBy(Function(path) Int32.Parse(System.Text.RegularExpressions.Regex.Match(Path.GetFileName(path), “\d+”).Value)).ToArray()
For Each filePath In sortedFilePaths
Log Message: filePath
End For Each
Hi
Directory.GetFiles(Fol_Path).OrderBy(Function(F) New Fileinfo(F).SizeInKB).ToArray
Try this
what is the variable type of sortedfilepaths?
is it string of array ?
@rlgandu
Thanks in advance
regards
@kmaddikatla
Parvathy
(PS Parvathy)
August 10, 2023, 7:33am
9
Hi @kmaddikatla
=> Use the below syntax in Assign activity: Mention your folder name.
filePaths= Directory.GetFiles("C:\Users\"+Environment.UserName+"\Documents\UiPath\4\Folder 1")
FilesArray= filePaths.OrderBy(Function(path) CInt(System.IO.Path.GetFileNameWithoutExtension(path).Split("_"c)(1))).ToArray
Both filePaths and FilesArray are of type Array(System.String)
=> Run a for each for FilesArray
Print a log message.
Refer the workflow for reference
Sequence22.xaml (9.8 KB)
Hope it helps!!
Hi @rlgandu ,
getting an error" Getfilename is not a member of string
Thanks in advance
regards ,
@kmaddikatla
Thank you so much @Parvathy ,
This is working
1 Like
Parvathy
(PS Parvathy)
August 10, 2023, 8:21am
12
You’re Welcome @kmaddikatla
Happy Automation
Regards,
system
(system)
Closed
August 13, 2023, 8:22am
13
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.