[英]Python: Move files from Folder and subfolders to another similar directory
我有两个源文件路径:
C:\Same\Path\To\File\unknown\ C:\Same\Path\To\File\unrecognized\
还有一个目标路径:
C:\Same\Path\To\File\Import
所有这些路径的子文件夹都相同。 它们是10-15个文件夹,具有3位数字的名称(例如233)。
如果源路径的这些子文件夹中有任何文件,我想从该目录中将其剪切掉,然后将其发送到与源路径相同的目标目录中。 我是python的新手,所以将不胜感激。
我认为您想要的是shutil.move
( py3k docs ):
Help on function move in module shutil: move(src, dst) Recursively move a file or directory to another location. This is similar to the Unix "mv" command. If the destination is a directory or a symlink to a directory, the source is moved inside the directory. The destination path must not already exist. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics. If the destination is on our current filesystem, then rename() is used. Otherwise, src is copied to the destination and then removed. A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over.
查看shutil
模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.