Home > Mobile >  Rename file names from file1..file1000 to file1001...file2000 using python
Rename file names from file1..file1000 to file1001...file2000 using python

Time:10-29

I found it difficult to rename the files. I have a scenario where I have to change a thousand files from filenames file1..file1000 to file1001..file2000. I am using Linux OS and trying to change file names using a python for loop. I could concatenate the file names using the command below, but couldn't change the file names sequentially.

for i in file*; do mv -i "${i}" "${i/file/file100}" ; done

CodePudding user response:

You could use shutil.move():

import shutil

for i in range(1, 1001):
    shutil.move("file{}".format(i), "file{}".format(1000   i))

CodePudding user response:

Or just stick with bash and use the same logic:

for i in {1..1000}; do mv file${i} file$(( $i   1000 )); done
  • Related