How to rename file names using text file in python -


i need rename bunch of files in folder new name reference text file. can please give example this.

my new names in text file:

1ba 1bb 1bc 1bd 1be 1bf 1c0 1c1 1c2 1c3 

like this.

updated code:

import csv import os  open('names.txt') f2:          filedata = f2.read().split(",")          os.rename(filedata[0].strip(), filedata[1].strip()) f2.close() f2 = open ('lines.txt','w') f2.write(filedata) f2.close() 

what using csv (comma separated) file input in format oldpath, newpath , following:

import csv import os  open('names.csv') csvfile:      reader = csv.reader(csvfile)      row in reader:          oldpath = row[0]          newpath = row[1]          os.rename(oldpath, newpath) 

alternatively, if want move file directory/filesystem can have @ shutil.move


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -