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)
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”?
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.
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…
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)
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
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.
@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.
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.
regex= New Regex ("^Input_[0-9]*_223455_[0-9]*$")
(From fItem As String In IO.Directory.GetFiles(filepath,"*.zip") Where pattern.IsMatch(IO.Path.GetFileNameWithoutExtension(fItem)) Select fItem).ToArray
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
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