Dynamic File copy, rename, and delete old file workflow in StudioX environment

Hi All,

I would like to build below workflow with StudioX. I found that ‘Assign’ function cannot be used in this environment, can you please help if you have an good idea.

  1. Copy latest csv file from folder A to B
    csv file is generated in folder A every business day, and its name includes MM-DD-YYYY kind like “Workfile_TypeA_05-24-2023.csv”, so I want to search the latest “Workfile_TypeA_*.csv” file and copy it to folder B

  2. Change CSV name in folder B
    After copy the csv file in folder B, I would like to change the csv file name kind like below.
    “Workfile_TypeA_05-24-2023.csv” → “Operation_20230524_V1.csv”
    I would like to convert MM-DD-YYYY in original name to YYYYMMDD then rename it.

  3. Remove old CSV file in folder B
    There must be only one csv in folder B, so after step 2 I would like to delete previous file such as “Operation_20230523_V1.csv”. just refer to ‘Date modified’ field in both file and remove older one.

Thank you for your help.

Tomohiro

Hi @tomohiro.osaki

Welcome to the community. Please find the solution below:

  1. Create a new StudioX project:
  • Open UiPath StudioX.
  • Click on “Blank Project” to create a new project.
  1. Add the required activities to your project:
  • Drag and drop the “Find Files and Folders” activity from the “Files and Folders” category into the Designer panel.
  • Configure the activity as follows:
    • Set the “Path” property to the path of folder A.
    • Set the “Search pattern” property to “Workfile_TypeA_*.csv”.
    • Set the “Recursive” property to False.
  • Drag and drop the “Copy File” activity from the “Files and Folders” category into the Designer panel.
  • Configure the activity as follows:
    • Set the “Source” property to the result variable of the previous activity (e.g., FindFilesAndFolders.Result.FirstItem.Path).
    • Set the “Destination” property to the path of folder B.
  • Drag and drop the “Rename File” activity from the “Files and Folders” category into the Designer panel.
  • Configure the activity as follows:
    • Set the “Path” property to the path of the copied file in folder B.
    • Set the “New name” property to the desired format (e.g., "Operation_" + Now.ToString("yyyyMMdd") + "_V1.csv").
  • Drag and drop the “Delete File” activity from the “Files and Folders” category into the Designer panel.
  • Configure the activity as follows:
    • Set the “Path” property to the path of the old file in folder B.
  1. Save and run the project:
  • Save your project.
  • Click on the “Run” button to execute the workflow.

This workflow will find the latest CSV file in folder A, copy it to folder B, rename it according to the desired format, and delete the previous file in folder B based on the “Date modified” field.

Make sure to adjust the folder paths and other details based on your specific requirements.