Renaming a file upon saving

Hi guys,

Just started using UI path.

I have been trying to do the following

  1. Download an attachment from outlook and save it in a folder
  2. Get file name of the attachment and then rename it using the move activity.

I am not knowing how to use the get file name activity if there is one or how do we get the file name and rename that ?

Hy @Shivaram_Panchagnula

I will give you directions assuming you are using Outlook.

  • Use the get Outlook mail activity to extract a list of all emails in a specific folder.
  • loop through the emails using the for each activity
  • check for the email properties mail.attachment
  • from there you can get the name of the file
  • use the download attachment activity to download the file wherever you want

Did you managed to do it on your own or do you need any more help?


Hello @William_Blech_Sister, in my case I dont even need to download a bunch of mails because I run the script only when I see the mail I need to work on.
So the condition I created is when I run it, it looks in the first 15 mails for the one that has an attachment and then downloads it to a specified path. Now i want rename it for which i need to move it right ?
But to move, I need to know the file name which am not knowing how to extract.
Sorry, my question might be a basic one. Trying to learn stuff :slight_smile:

So, maybe my real question is, how can I know the name of a file that exists in a folder and then use that in the move activity to rename it

Hy @Shivaram_Panchagnula,

There is a function for that: directory.getfiles(your folder path). It returns an array of strings with the files full path. You can use a for each loop to itenerate thought the files. Is that what you need?


Perfect !! Thank you very much !! I used the activity and it worked.

Now am facing the next hurdle.

1 The read and write range is not maintaining the formatting of my source file.
2 The range for example J1:J260 that i copy from the downloaded file, I paste it from cell J1 in the destination file. But i notice that always pastes from J2 instead of J1 thereby causing a mismatch always.

What am i doing wrong in both the cases.

Thank you in advance !

1 Like

Hy, check if the add header option is active on the write range option, it makes sense

Yes you are right. I removed the add header and it worked properly, but still trying to figure out how to retain source formatting in destination file.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.