Batch modification file name
import os
dir = os.getcwd ()
dir = Os.chdir (R ' C:\Users\Administrator\Desktop\cupdata ')
j = 0 for
file in Os.listdir (dir):
#os. Listdir ('. ') Traverses each file name within the folder and returns a list if file[-2 containing the file name
:] = = ' py ':
continue #过滤掉改名的. py file
os.rename (File,str (j) + '. JPG ')
j+=1
Print (file) #
print (dir)
# # dir = ' c:\windows '
# # if Os.path.exists (dir):
# # print ("Hello World") # #
Else: # print ("Hello World1")
Modify file name while writing file name to TXT file
import os
dir = os.getcwd ()
dir = Os.chdir (R ' C:\Users\Administrator\Desktop \img ')
f = open (R ' C:\Users\Administrator\Desktop\bg.txt ', ' a ')
j = 0 for
file in Os.listdir (dir):
#os. Listdir ('. ') Traverses each file name within the folder and returns a list if file[-2 containing the file name
:] = = ' py ':
continue #过滤掉改名的. py file
os.rename (file, ' BG ' + Str (j) + '. jpg ')
f.write (' Img/bg ' +str (j) + '. jpg ' + ' \ n ')
j+=1
print (file)