Copy each File name from saved attachement

Hello,
I’m using the Get Outlook Mail Messages activity to read new email and save the attachements to a folder in my F:drive. I want to copy part of the file name and seach for that number is an excel sheet, each attachment will have different numbers.

So far I am able to get the mail and save them to the folder but cannot copy the number in the file name.

Any advice is greatly appreaciated.

Thanks
Scott

Hi @scotthutton

I had worked on a similar case.
I will give you a shallow view on this.

Run a loop on the downloads folder to save the filename of all attachments.
Now just do the string manipulation to get the data from the filename you want.

Do let me know if you are unable to do. i can share my workflow.
Also, provide us the filename example to help you with string manipulation

Use Directory.GetFiles(folderpath) to fetch the filenames from specified folder. You can also specify the file type if you want to retrieve only one type of files (Like, pdf or xlsx)

Iterate through the file names, get the required values from the filename and do required processing

1 Like

Hi @chandu4712 thanks for replying, would you mind sharing your workflow? I work better off seeing an example.

Thanks
Scott

sure. will be back in some time.

meanwhile, can you share the filename example? and the data to be extracted from the filename

NEW.xaml (10.9 KB)
@chandu4712 see attached workflow. the file name is username-staffnumber.pdf, all i want to extract is the staffnumber, there will be at least 90 files to do this for. once the staffnumber is copied i want to search for it in a excel file to get a code then open the file and print.

You can use string manipulation in “For each File” to get the staff number from each file then once to have the staff number.

Hi @scotthutton

Please check below workflow
Main.xaml (9.2 KB)

  • I am checking for the existence of downloads folder
  • Get all the file names in a list
  • Data manipulation for fetching staffnumber.
    -P.S. filename assumed as in the below screenshot.

files

I am able to get below result

result

Hi @chandu4712 got the following error:

“message”: “Write Line: Index was outside the bounds of the array.”,

@scotthutton

I had assumed the filename as shown is the image in my earlier response.
You would definitely get an error because filename you are referring will be different.

I don’t have the file name format you are getting.
You have to design the data manipulation part according to the name.
Or let me know the format you are having

Sorry I’m still really new to UI Path and struggling with the data manipulation part, in which activity does this need to be done

i am manipulating the data in ‘for Each’ loop of my workflow.
Where i am fetching the data from filename.

Please share a dummy filename same as yours so that i can create a sequence for same.

dummy file name - TEXT-1234567

this is the same format as i have designed.
This should work perfectly.

Can you check these:

  • You have provided correct folder location.
  • All the files in that folder has same naming format.
  • the workflow i attached will fetch the second component delimited by ‘-’. So your staffnumber is always on the second position in the filename.

Try debugging the workflow. and if this doesn’t works you share you workflow possibly.
I will get this cleared.

1 Like

Strange, it now works without changing anything.

Okay so I know at the end of that sequence what is it doing so I can proceed to the next step.

1 Like

can you mark my answer as solution if this works :smile:

Will do, is the sequence coping the staffnumber? If not how do I go about that?

yes, you see the staffnumber in the output panel. correct?

Use the same code as in write line in Assign Activity to store your satffnumber in the variable.

Use this variable to search in the excel or your workflow further as you stated.

1 Like

No I see the first name of the file only.

As you specified earlier i can understand that,
your filename is TEXT-1234567
TEXT is the Name of file at ‘0’ position
1234567 is the staffnumber at ‘1’ position

so in the sequence, in write line Activity, if you give filename(1) it will give you 1234567 as output.
So this should give you correct output. What exactly are you getting?

1 Like