Creating copies of excel files

Hi, I’m fairly new to UiPath and I’m trying to create a process where UiPath will make a copy of the last excel file in a folder and give it another fixed name


 Use Assign:
filesArray = Directory.GetFiles("C:\YourFolderPath")-->Array of string
Use Assign:
lastFile = filesArray.OrderByDescending(Function(f) New FileInfo(f).LastWriteTime).First()
 Drag Copy File Activity


Follow this approach.


Just instead of Write line use Copy File. In this activity To property you can configure your another fixed name.

Ashok :slight_smile:

Hi @darco

To get the latest file use the below syntax:

latestFile = Directory.GetFiles("C:\Your\Folder\Path").OrderByDescending(Function(f) New FileInfo(f).LastWriteTime).FirstOrDefault()

You can use Copy File and copy the latest File and Rename the copied latest file.


Hi @darco

latestFile = Directory.GetFiles("C:\YourFolderPath", "*.xlsx").OrderByDescending(Function(f) New FileInfo(f).LastWriteTime).First()

Path.Combine("C:\YourFolderPath", "NewFileName.xlsx")



Hii @darco

-Use the “Assign” activity to set a variable for the folder path.
-folderPath = “C:\Your\Folder\Path”

-Use the "Assign"activity to get all files in the folder.
-files = Directory.GetFiles(folderPath, “*.xlsx”)

-Use the “Assign” activity to get the latest file.
-latestFile = files.OrderByDescending(Function(f) New FileInfo(f).CreationTime).First()

-Use the “Assign” activity to set the new file path with the fixed name.
-newFilePath = Path.Combine(folderPath, “FixedFileName.xlsx”)

Use the “Copy File” activity to copy and rename the file.


Those variables are unnecessary. Just put the expressions into the Copy File activity, and both expressions can be combined into one.

You don’t have to create all those variables. Just put…

Path.Combine(Directory.GetFiles(folderPath, “*.xlsx”).OrderByDescending(Function(f) New FileInfo(f).CreationTime).First(),"Filename.xlsx")

…into the Copy File activity.

1 Like