Count number of files with variable

Legends,

I am new to building BOTs.
I am trying to find the number of files - PDF, with similar number in the name.
STRORDERNUM - is a string which i defulat to 36 for my testing however this variable flows from different flows

My Variable
FILENUM = Directory.GetFiles(“--------DATA\06. PNT - Plant\01 Planning\14. Work Order Generator\Work Orders"+”_“+strOrderNum+”.pdf").length

so if strordernum = 20
file names like
A_20_SAB.pdf
B_20_XYZ.pdf

FILENUM = 2
However everytime i run i get illegal character message

@Saurabh_Grover
From the example file names you provided; the file name pattern is *_orderNumber_*.pdf

VB

Dim OrderNumber = 20
Dim NumberOfFiles = System.IO.Directory.GetFiles("C:\users\abc\Desktop\reports\", "*_" & OrderNumber & "_*.pdf").Length

C#

var OrderNumber = 20;
var NumberOfFiles = System.IO.Directory.GetFiles(@"C:\users\abc\Desktop\reports\", "*_" + OrderNumber + "_*.pdf").Length;

In C# code note the @ symbol to escape the \ character. If you are not using @, you need to use double slash (\\) instead of single slash (\).

1 Like

Thank you KannanSuresh,
have managed to find number of files by C#, appreciate your prompt reply.
Can you please suggest - I am trying to merge PDFs, where
A_2_Z.pdf
B_2_X.pdf

2 = strordernum, for this i have used below which i think gives me an error, can you suggest

Filelist - {“M:-----------\14. Work Order Generator\Work Orders",”“+strOrderNum+”.pdf",“M:\M487----------------t\01 Planning\14. Work Order Generator\Work Orders",”“+strOrderNum+”.pdf"}

I am trying to attach files like below
A_2_Z.pdf
B_2_X.pdf

New File - 2_C

System.IO.Directory.GetFiles will give you a string array of the files that match the criteria. Find file names using that instead of concatenating string.

1 Like

Dear Kanan,

Thanks for your help, one hurdle cross. however my situation is to get files from two different folder where they contain the same name which STRORDER. SO the name in two folders is always
Folder 1
A_STRORDER_123
Folder 2
B_STRORDER_134
Bot should merge them and store at a different location the name would be
B_STRORDER_134

For this i am trying to get all files from directory merge options and using below
I am first trying to get directories however it is a failed attempt
image

system.io.Directory.GetDirectories(“M:\XYZ\DATA\06. PNT - Plant\01 Planning\14. Work Order Generator\Work Orders\AllCombinedAttachments",“M:\XYZ\DATA\06. PNT - Plant\01 Planning\14. Work Order Generator\XYZ 3.5.21"”“+STREOrderNum+”.pdf”,SearchOption.AllDirectories)

This is accepted, however running this shows illegal characters?
Would you have any idea how to acheive merging PDF with almost similar names from two different folders?

@Saurabh_Grover - You would like to merge two pdfs from different folder with the name of B_STRORDER_134 right??

If yes then please try like this in the Join PDF File activity

FileList =   directory.Getfiles(YourFolder1,"*.pdf").Concat(Directory.GetFiles(YourFolder2,"*.pdf")).ToArray

Output File Name  = "B_STRORDER_134.pdf"

Hope this helps…

Note: Instead of *.pdf , you can adjust it to your requirement

1 Like

Thank you prasath, this happens to get me the files from different location. I accept this as a solution. As I am learning more of such strings, is there a document or a library you can direct me to if i am stuck on such equations and want to learn further. - thanks

I do lot of search in the forum in the beginning when I started learning UiPath, And when I see a new/good formula I will bookmark that solution and also copy the formula to my personal sheet and immediately I create a practice exercise to execute this. This helped me a lot.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.