If statement is inside a FOR EACH loop
file in WithYearFilesFolder
file = object (eg. pdf file )
I want to check if the file extension is a pdf and move it.
Thanks in advance
If statement is inside a FOR EACH loop
file in WithYearFilesFolder
file = object (eg. pdf file )
I want to check if the file extension is a pdf and move it.
Thanks in advance
Hi @samuel.chaane,
You can use Path.Contains(".pdf")
inside your if statement. See below for what I use to read doc and pdf texts:
Is still it cant identify the extensions. I will try it again
How are you getting your file array? You can set your For Each TypeArgument
to string and then check the data with the code I used above
Best Regards,
Vrushali
Hi @samuel.chaane,
You can declare the variable filename =path.GetFileName(file.ToString). This will return the filename instead of full file path.
in if condition you can check path.GetExtension(filename)=“.pdf” , here you can check filename (variable declared in step 1) exact extension.
.Contains may not be robust in some scenarios where your file itself contains .pdf(for example, pdf.pdf) as name, but this could be a very rare scenario
And if you haven’t already done it, remember to convert the string to lower case before comparing it. If not, you might miss pdf files with caps in the extension, e.g. “Example.PDF” or “IMPORTANT.PDF”.
Path.GetExtension(filename).ToLower = ".pdf"