我搜索并编写了这样的代码,但不起作用。请推荐我。我下载了大量的媒体文件。我想在上面加上序列号。此代码不工作,但甚至不会注意到错误。请帮帮我
import os
path = os.getcwd()
dirc = os.listdir(path)
n = 0
for file in dirc:
os.chdir(path)
if file.endswith('*.txt'):
rename(srt(n) + file, file)
n += 1发布于 2019-11-14 19:07:00
import os
path = os.getcwd()
n = 1
for filename in os.listdir(path):
if filename.endswith('.txt'):
src = path + '\\' + filename
dst = path + '\\' + str(n) + '-' + filename
os.rename(src, dst)
n+=1上面的代码用1-abcd.txt替换文件名abcd.txt,依此类推。
https://stackoverflow.com/questions/58854772
复制相似问题