How to rename the randomly generated download file and then move

Hi Team,

I want to rename the file which is downloaded to downloads folder.

Steps I followed:
Using Assign activity, I get the latest downloaded file using
str = String.Join(“”,Directory.GetFiles(dirFilepath_Source,File_Type,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))

Using Move Activity, source location to destination location folder.

Here source location as “str” the place where downloaded file available but not sure on the filename and its randomly generated.

After download, reading one more data from the application and saving in a “variable”.

Rename file should look like “Variable”_Filename.

My requirement is to rename the filename and then move (or) move and then rename.

I am not able to rename the file. Please suggest.

1 Like

Hi @katakam26

Check this

Thanks
Ashwin S

Use File.Copy → This will take source file and copy to a target by as specified.

@katakam26

Are you able to find the latest downloaded file or not ?

Once found the file then download this package and try it.

https://go.uipath.com/component/rename-file-c53139

If you have any doubts then please let me know.

@ Lakshman
As per the “Rename File”- I need to provide the below details

  • FilePath: C:\Users\Desktop\oldName.txt (Full file path)
  • NewFileName: newName.txt (file name)
  • IsRenamed: It will give output as boolean value. It returns true if operation succeed else False.

Queries:
oldName I am not sure- It is randomly generated
My new name should be customText_oldFileName. Here the custom text also randomly generated from the web application.

If you know the exact file name in advance then it will works, what if file name should know once it is successfully downloaded and randomly generated from web application.

Please suggest. Thanks for your time.

I found the solution like this

  1. After move, assign the below string to variable1.
    String.Join(“”,Directory.GetFiles(dirFilepath_Source,File_Type,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))

  2. You variable1 is having the latest file name along with the path like C:/A/B/C/Downloads/RandomlyGeneratedFilename

  3. Create a array string variable.

  4. Using split string method
    StringVaraible.Split({“Downloads/”},StringSplitOptions.None)

  5. Now your array string variable having the values are
    array string variable(0) is having the value as “C:/A/B/C/Downloads/”
    array string variable(1) is having the value as RandomlyGeneratedFilename

  6. Move file activity Destination as: rename the file as
    “customized string” + RandomlyGeneratedFilename

Thanks for all your time.

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