Python - 如果目录包含以...开头的文件...移动文件
我需要在 Python 中创建一个脚本,该脚本将查找一个目录(仅包含一个文件),如果该文件不是当天的文件,则将其移动。作为参考,该文件有一个与当天相关的后缀(myfile_030811.xls
)
有人对此有任何想法吗?
I need to create a script in Python which will look to a directory (which contains only one file) and move it if the file is not for the current day. For reference the file has a suffix which relates to the current day (myfile_030811.xls
)
Does anyone have any ideas for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个?这假设当前目录下存在一个名为“archived”的目录。您可能想调整它以满足您的需求。另外,这还假设您目录下的所有文件都具有结构 _ddmmyy 的名称。格式。否则它不会工作
try this? This assumes that a directory called 'archived' is present under the current directory. you might want to tweak it to suit your needs. Also this assumes that all files under your directory have a name of the structure _ddmmyy. format. It won't work otherwise
巴什怎么样?
测试一下:
如果一切看起来都不错,请删除 mv 前面的“echo”命令。
How about bash?
Test it with :
If everything looks good, remove the "echo" command in front of mv.