Rename Two files at a time

Hi all,

I have downloaded two sheets i.e,
1.7166a12c-4d74-4073-87a4-321b63d7758a-canada.csv
2.7166a12c-4d74-4073-87a4-321b63d7758a-united_states.csv
I need to rename the files i.e, I want to rename them as

  1. canada.csv
  2. unitedstates.csv
    Someone help me in solving this.

@Anveshs,

Check this,

Path.GetFileNameWithoutExtension(“7166a12c-4d74-4073-87a4-321b63d7758a-canada.csv”).ToString.Substring(Path.GetFileNameWithoutExtension(“7166a12c-4d74-4073-87a4-321b63d7758a-canada.csv”).ToString.LastIndexOf("-"c) + 1) + “.csv”

@Anveshs

Try this.

csvFiles [] = Directory.GetFiles("Folder path","*.CSV")

Then use ForEach loop activity to iterate one by one file and rename it like this.

  ForEach item in csvFiles
       fileName = Path.GetFileName(item)
       newFileName = fileName.Split("-"c)(5).Replace("_","")
       Use **Rename File** activity to rename file and pass source as **item** and Destination as **newFileName**.

Note: Go to Manage Packages and then Go package source and then download Rename File activity.

1 Like

Anyone please help me solving this.
I need to change the names of both the files at a time.

Hi @lakshman

Unable to solve the problem. Please provide me an alternate solution.

RenameCsvFiles.xaml (6.1 KB)

Change the directory and try with this, you need to delete your old file since we have created a new file with new name.

@Anveshs
Try this solution to rename files.
Main.xaml (6.0 KB)

1 Like

Hi @Anveshs,

You need to split the string, keeping “-” as delimiter and get the element of last index.

str = “7166a12c-4d74-4073-87a4-321b63d7758a-united_states.csv”
arrayStr = str.Split("-"c)
fileName = arrayStr(arrayStr.Length - 1).Replace(“_”,“”) // To get last element which is file name and optionally you can replace “_” with “”

Now you can use Move activity to rename it.

1 Like