从 manu-fatto 开始,至少这表明了从名称filename
到destdir
名称的转换。
shutil.move(src, dst)
尽管我认为您必须小心,但以不同的方式移动文件可能会有所帮助。
import os.path
def destdir(filename):
f = int(os.path.splitext(filename)[0])
d = (f - 1) // 10
return "%02d-%02d" % (10*d+1,10*(d+1))
def filenames():
"""OP to write implementation"""
n = 23
for x in range(1, n + 1):
yield "%02d.txt" % x
for filename in filenames():
print filename, destdir(filename)
输出:
01.txt 01-10
02.txt 01-10
03.txt 01-10
04.txt 01-10
05.txt 01-10
06.txt 01-10
07.txt 01-10
08.txt 01-10
09.txt 01-10
10.txt 01-10
11.txt 11-20
12.txt 11-20
13.txt 11-20
14.txt 11-20
15.txt 11-20
16.txt 11-20
17.txt 11-20
18.txt 11-20
19.txt 11-20
20.txt 11-20
21.txt 21-30
22.txt 21-30
23.txt 21-30