Get file extension with for each row

Hi,

So, I have a For Each Row activity to filter some file names from excel (which I’m storing on a data table).

But then I need to access a path with multiple files and move the files that were found above.
The thing is, I can’t find a way to get the extension on for each row, if I try to do something like "filename & “." it outputs like "invoice_123.” instead of “invoice_123.pdf”.

It isn’t only .pdf’s btw, it can be a lot of file types.

Any tips guys?
Thank in advance!

Hi;
Where do you have the full information about the file name "invoice_123.pdf”?

@pravin_calvin thank you, but it doesn’t happear to me :confused: image

Hi @Nadia_GHOUFA , on a variable named “Path” that’s where all the files are

@cteixeira -Its path.getextension(yourpath)

Hi @cteixeira

Can you send me a screen shot of path which you are getting from the datatable?

Thanks

It doesn’t recognize it :confused: image

The paths isn’t from the data table, the dataTable only has the file name from the excel, then I’m using PathFiles + DTDeceased.rows(counter)(0).ToString and trying to merge with “.*”

@cteixeira - is this what you are trying to fetch??

It’s something similar to that, but I don’t want all the files in the directory, only the ones that are named on my excel file which I output to a dataTable (but on the excel I only have the filename, not the extension, and it can be .pdf, .docx, .xlsx, .png etc etc)

@cteixeira - so you have the file name listed on the excel file and you are reading the files right?? while reading you just want the extension of that file which you reading??

path.getextension(row(“Filename”)).tostring…

No, while reading, I need the filename + the extension, what I’m using to get the file name is "DTDeceased.rows(counter)(0).ToString" but if i try to add & “.*” it outputs it like this: “invoice_123.*” instead of “invoice_123.pdf”

@cteixeira - Please post your input file screenshot and workflow where you got stuck?

Here the workflow: !workflowimage|288x500
What it looks on excel: !excelimage|177x62

@cteixeira - Really sorry…still i am not able to get exactly what you are trying to do? and the screenshots are not informative too…

I believe it should work with:

arrFiles = Directory.GetFiles("C:\YourPath", DTDeceased.rows(counter)(0).ToString + ".*")

It returns an array of string with all the matching files.

Example:

image

image

1 Like

I will try that thank you!
Can you please just let me know how can I output the array?

So…

  1. I have a DataTable with file names without extensions “invoice_123” (it can be any extension)
  2. I have a folder with a lot of files including the ones that are on the Datatable
  3. I need to move those files mentioned in the DataTable to another folder

A For Each loop is recommended since you don’t know how many matches you will get:

image

@cteixeira - Please find the starter help here…Seach_And_MoveFiles.zip (48.5 KB)

Run this workflow as is, you will see the files get moved to the “Moved” folder where jpeg file with unmatched searched left in the “SearchFolder” itself.