|
发表于 2022-7-22 11:06:03
|
显示全部楼层
本楼为最佳答案
本帖最后由 jackz007 于 2022-7-22 11:37 编辑
- import os
- import shutil
- def foo(spath , rpath , n):
- e = []
- for file in os . listdir(spath):
- x = os . path . join(spath , file)
- if os . path . isfile(x):
- if len(file . split('.')[0] . strip()) < n:
- shutil . move(x , os . path . join(rpath , file))
- else:
- e . append(file)
- for i in range(len(e) - 1):
- for j in range(i + 1 , len(e)):
- if len(e[i]) > len(e[j]):
- e[i] , e[j] = e[j] , e[i]
- elif len(e[i]) == len(e[j]) and e[i] . lower() > e[j] . lower():
- e[i] , e[j] = e[j] , e[i]
- return e
- with open("filelist.txt" , "wt") as fp:
- for x in foo('D:\\00.temp\\sss' , 'D:\\00.temp\\ttt' , 6):
- fp . write(x + '\n')
复制代码 |
|