Search in folder and upload pdf Files to web

Hello
I’m doing an automation process with loading pdf files in webpage tickets.
These pdf files are P.O. and they are located in a specific folder named TEMP and they are saving from SAP with the next name rule “Orden_de_compra_4700219066.pdf” (Purchase_Order_numberP.O)
imagen
I’m clear with I must to read the workbook with the data, and then use a “For each” to go row by row
my question is… How can I select the correct name file, if in the workbook they were save with only number P.O.: “4700219066”?

Thanks in advance for your help.

Directory.GetFiles(FolderName, SearchOption) returns an array of files from the specified path.

If you want to extract only the PDFs from that folder, you could use “*.pdf” as SearchOption.

So, Directory.Getfiles(“C:\Pdfs”,"*.pdf") will return an array with the names of all pdfs from PDFs folder.

Hello @Francisco_Morales,

you can use Path.GetFilename(Dir_Loc). it gives all files name present in Directory.
use for each loop and split name of the file based on “_” or use Regex to read only numeric number.

Thank you!

Best Regards,
@ak3430

Only there are PDF files.
But I need to find the P.O. numbers which are in Excel file and select them from the folder to upload on web page.

Thanks for your comment

First part is Ok
archivos

if the pdf name format is fixed and standard.
you can you use the directory.getfiles(“path”,“orden_de_compra_”+POnumber+".pdf") - which returns the array of pdf files which you required…

you can use array to upload… :slight_smile:

Hi @venkat4u
Finally I’ve achieve to extract POnumber.
With Directory.GetFiles(“path”,“orden_de_compra_*.pdf”)
then…
I used two assigns inside of “For Each” (to iterate fileList)
imagen

Now, I’m doing an “If” comparing var numeroOC (POnumber) with the PO number inside of excel
numeroOC = row(6).ToString

if both are equals, the file will be attached in corresponding ticket

I don’t know if this would be the best way, but I’m moving forward

Thanks at all for your tips

1 Like

This would have been an optimal solution as you would not have to loop through each file to compare.

What you are already doing is get all files

so you can actually, get the number from excel into a variable ‘POnumber’ and then add that to the search criteria.
Post that you can do a count check and then proceed with the next item in the excel sheet.

You would be having one less loop and that makes a lot of difference. :slight_smile:

2 Likes

@nadim.warsi can u help on getting File from folder?

Input----- folder contains zip Files(Count lakh files) whose name format as below

           Input_456746544_223455_38373323.Zip

i want get file based on middle number, Other 2 numbers will change from one file to another file.
i Know i can give * in Pattern for searching any value, But is there any way to check only numbers.

1 Like

sorry for the delay.
So, if i get it correctly then your seacrh should return all the files for Input_[ShouldBeNumbers]_223455_[ShouldBeNumbers].Zip

This works for the above scenario.

  1. regex= New Regex ("^Input_[0-9]*_223455_[0-9]*$")

  2. (From fItem As String In IO.Directory.GetFiles(filepath,"*.zip") Where pattern.IsMatch(IO.Path.GetFileNameWithoutExtension(fItem)) Select fItem).ToArray

Result:

1 Like

@nadim.warsi Can we do samething(same regex) in below statement,

directory.getfiles(“path”,“orden_de_compra_”+POnumber+".pdf")

1 Like

You can but only in the case where you want all PO files with that pattern in a folder where lot other files are also present.
But @Francisco_Morales only wants to search for a specific PO that he has coming from his excel and see if that is there in the folder

2 Likes

@nadim.warsi Ur saying we cant use regex. Is that correct? If it is not correct can u give regex pattern for my case using Directory.GetFiles command.

1 Like

If he uses regex then he will get all the pdf files then he will have to loop through each to compare.
He already has a loop for excel rows, so if he just used that excel item to get the files and the result is 0 or 1 then its simpler than loop1(excel row){ get all files - loop2(each file)}

regex - result > 1
directory.getfiles(“path”,“orden_de_compra_”+POnumber+".pdf") - 1 or 0 result

2 Likes