How to rename part of a file to its corresponding value using part of its key

How can I rename these file to to its corresponding values using key, key may not be exact to the file name part but both the key and parts of the file name has similar name which is A1.

MASTER FILE.xlsx (19.5 KB)
1.File- A2.docx (15.4 KB)
1.File- A1.docx (15.3 KB)
these are the files

Hi @Helpmepls

Please check the below attaced Xaml File

Practice.zip (2.1 KB)
It Helps!

image
what location do i put for value to save
and could you explain each part of your process. thanks

  • Assign key = “” (initialize an empty string)

  • For Each file in Directory.GetFiles(directoryPath)

    • Assign key = “” (reset the key for each file)
    • For Each potentialKey in keys (where keys is a list or array of possible keys)
      • If file.Contains(potentialKey) (check for similarity)
        • Assign key = potentialKey (set the key)
    • If key <> “” (a valid key was found)
      • Assign newFileName = Path.GetFileNameWithoutExtension(file) + “_” + key + Path.GetExtension(file) (construct the new file name)
      • File.Move(file, Path.Combine(directoryPath, newFileName)) (rename the file)

image
i have this error

@Helpmepls

Keep the folder location where the files are located

yes i put it correctly but still have this

@Helpmepls

If the key is always <RequiredValue Name>

Then please follow

  1. Read the data into datatable dt
  2. Now use for each file in folder with "*.docx" as filter
  3. Use lookup datatable activity and pass the column index as 0 and value to search as "<" + currentFile.Name.Replace(currentFile.Extension).Split("-"c)(1).Trim + " Name>" and save the output variable and give output column index as 1 and say output variable is str
  4. Inside loop use rename file activity…pass file as currentFile.FullName in rename field pass currentFile.Name.Replace(currentFile.Name.Replace(currentFile.Extension).Split("-"c)(1).Trim,str)

Cheers

Could you sent me in UiPath as im still new to this hence im asking for help. thank you

Cheers

but what if my keys are different, these are the files
MASTER FILE.xlsx (19.5 KB)
1.File- A2.docx (15.4 KB)
1.File- A1.docx (15.3 KB)

Hi,
Find the attached file

Practice.zip (2.1 KB)

I keep getting this error

I think is because the variable Doc_name contains RP, the error is something there but im not sure, do let me know

@Helpmepls its because of there is no key in the dictionary with that name please the key name in the dictionary

how do i do that is it possible to sent a updated one using key and value in the excel i sent to you

Cheers

image
is there something wrong with this, do let me know as im confused, i thought the keys are in the excel file i sent why need manually key.

cheers

any updates? thank you