Check the file name before renaming

how do i put a if statement before the rename file part to which if the soon to be rename has already exist in the folder then dont rename that and go to the next?

Hi please check the below steps

Assign activity: folderPath = “C:\YourFolderPath”

For Each activity (item in Directory.GetFiles(folderPath))
Assign activity: newFileName = “NewName.txt”

If activity (Not File.Exists(Path.Combine(folderPath, newFileName)))
    Invoke Method activity:
        TargetObject: new FileInfo(item)
        MethodName: MoveTo
        Parameters: Path.Combine(folderPath, newFileName)


could you show in UiPath process instead of invoke code


i need it to fix this

That’s why you put the IF around it as I showed you. If the new filename doesn’t exist, rename it. If the new filename already exists, then what do you want to do?

but how do i find if file exist already in an if statement because i dont know how

how do i check if file in folder already existed?

Hi @superpunchypp ,
like a certain topic I suggested to you
We can call the current file name strCurrentName
Name the file we will change to strNewName
if strCurrentName = strNewName
→ no change,
else → change


Try below condition in if




it does not work as my currentfile is beofre changing, and only after changing is where there is same name as some in a folder


So you are renaming different files with same name?

Firstly why are you doing it…show the full process and explain what you wnat to acheive


i send you in message ok

Please clarify, I see you have a lot of topics, a lot of messages, but they only solve the same problem.
We can set up a quick meeting to resolve it, but first let’s clarify your request

Hi @superpunchypp ,

  1. First check if the name you want to change already exists with path exist
    it will give you boolean variable
    2.Here continue to check the boolean variable, if the name already exists we will not change it
    3.Next, if we don’t need it, we can delete that file

I already showed you that.

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