【发布时间】:2016-08-01 19:27:46
【问题描述】:
我遇到了这个问题...我想创建一个带有时间戳名称的新文件夹。然后我想把一堆文件移进去。
我想不通!
import shutil, os, time
timestr = time.strftime("%Y%m%d")
Sourcepath = r'Z:\\test'
if not os.path.exists(Sourcepath):
os.makedirs(Sourcepath+timestr)
source = os.listdir(Sourcepath)
destinationpath = (Sourcepath+timestr)
for files in source:
if files.endswith('.json'):
shutil.move(os.path.join(source,files),os.path.join(destinationpath,files))
【问题讨论】:
-
请在代码的每一行缩进四个空格(如果您的代码缩进更多,则更多)。然后阅读起来会更清晰。
-
运行代码时究竟发生了什么?你有追溯吗?还是不是您期望的结果?