How to create and replace the old docx with new rename

OK @superpunchypp ,
After test it success, I will sent to you
Cheer

1 Like

Hi, any updates, thank you

Cheers

use Python to invoke the Python script to do this its so easy to do.

Use below Code:
import os

# Specify the folder path
folder_path = r'C:\Path\To\Your\Folder'

# List all files in the folder
files = os.listdir(folder_path)

# Iterate through the files in the folder
for file in files:
    # Check if the file is a Word document (you can modify the condition accordingly)
    if file.endswith('.docx'):
        # Specify the old and new file paths
        old_file_path = os.path.join(folder_path, file)
        
        # Rename the file (replace 'Word' with the desired new name)
        new_file_path = os.path.join(folder_path, file.replace('Word', 'NewName'))
        
        # Perform the renaming
        os.rename(old_file_path, new_file_path)
        
        print(f"Renamed: {old_file_path} to {new_file_path}")

Make sure to replace 'Word' with the actual part of the filename that you want to replace, and 'NewName' with the desired new name.

If you dont know how to use python please check the below post I explain end to end and I given the python script and also I given Video for beginners

If you have any issues let me know.

Thanks,
Chethan P

1 Like

but my project not allowed to use invoke code

Hi @superpunchypp ,
image
my new update
Rename (2).zip (710.9 KB)
regards,

1 Like


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

Hi @superpunchypp ,
currentname = newname
cheer

which variable would be the currentname and newname

Hi @superpunchypp ,
The current name is file.toString
You can call the new name according to the renaming method I sent you in the previous source code
Cheer

is it ok if i send you my current process, I will send you a sample file to fix the current issue

ok, send it to me and I will fix it for you
Cheer

I sent, do let me know as soon as possible

Cheers

@superpunchypp

You need to use currentfile.name.equals(renamenewname)

Or

currentfile.name.Split("."c)(0).equals(renamenewname.Split("."c)(0))

Cheers

where do i put this in? can show in UiPath like a screenshot so i can do myself

@superpunchypp

Drag if condition and in the condition field paste this

Cheers

you said drag if condition but where do i put this if condition at ?

or is it this if condition?

@superpunchypp

You wnat the condition for rename…so place it at the point of rename…and move rename to the else side of if condition where ever you need

Cheers

yes i did that but in order for it to be same existing name for the if statement to run it has to be renamed first but since it has exist it cant be renamed

@superpunchypp

Then check in the folder if same file exists using this condition in if

Directory.Getfiles("Folderpath",renamenmename + "*").Count>0

This also to be used in if codnition only and on else side you have no file with name on then side you have a file with same name

Also rather than creating multiple topics for same and also asking same question incremnetqlly…it would be good if you can tell what all you need at once and maintain only ine topic…I see atleast 7 topics created for same which will not help anyone as every update will be in different thread

Cheers