gpt4 book ai didi

Python:将文件从文件夹和子文件夹移动到另一个类似目录

转载 作者:行者123 更新时间:2023-11-28 23:04:48 24 4
gpt4 key购买 nike

我有两个源文件路径:

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 issimilar to the Unix "mv" command.If the destination is a directory or a symlink to a directory, the sourceis moved inside the directory. The destination path must not alreadyexist.If the destination already exists but is not a directory, it may beoverwritten 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 ofthe issues this implementation glosses over.

关于Python:将文件从文件夹和子文件夹移动到另一个类似目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7113062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com