Python - About Scripting and Bubbling Algorithms

Write a script in Python (to modify the file name in a certain directory in large batches) :

 

import them

path=input('Please enter the file path (add / at the end:')

 

Get all files in this directory and store them in the list

f=os.listdir(path)

 

n=0

for i in f:

 

#Set the old file name (that is, the path + file name)

oldname=path+f[n]

#set new filename

newname=path+‘a’+str(n+1)+'.JPG'

 

#Use the rename method in the os module to rename the file

The rename method in the os module renames the file

os.rename(oldname,newname)

print(oldname,'=====>',newname)

 

n+=1

 

------------------------------------------------------------------------------------------

 

Bubble sort:

 

       The bubble sort method is designed to be like a form of bubbling in water. In each large cycle, the pair is compared, the decimal number is first, and the large number is pushed back, and the largest number is filtered out, ranked at the end, and excluded from the sorting as the largest number. , and then compare the remaining number sequences in a general way in the next big loop, and after looping the length of the list -1 times, the positive order of the list can be obtained.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325296911&siteId=291194637