[英]Shutil.move() function moved files into a folder which i cant open
I used shutil.move()
function to move some important files into desirable directory.我使用
shutil.move()
函数将一些重要文件移动到所需目录中。 The directory did not exist, So i gave the name as a parameter i shutil.move()
function.该目录不存在,所以我将名称作为参数指定给我的
shutil.move()
函数。 After the execution, it moved the files in a dir(Which does not seem to be a dir, when seeing properties it says its a "File") which i cannot open.执行后,它将文件移动到我无法打开的目录中(这似乎不是目录,当看到属性时,它说它是“文件”)。 can you please help me to open this file to extract my files??
你能帮我打开这个文件来提取我的文件吗?? The code was like this:
代码是这样的:
for file in Path("C/Users/Mahum/Downloads").glob(*.exe):
shutil.move(file, "E/New Folder")
The code executed with zero exit code but i got that problem.....使用零退出代码执行的代码但我遇到了那个问题.....
I think you have misunderstood what shutil can do.我认为您误解了 Shutil 可以做什么。
If the destination is a dir, then it will move the source file into如果目标是一个目录,那么它会将源文件移动到
that dir.那个目录。
However if the destination doesnt exist, it will rename the src as但是,如果目标不存在,它会将 src 重命名为
the destination.目的地。
If the destination does exist and its a file it will overwrite that dest file with the source file.如果目标确实存在并且它是一个文件,它将用源文件覆盖该目标文件。
So in you case lets say you had 5 files.所以在你的情况下,假设你有 5 个文件。 "E/New Folder" didnt exist.
“E/新文件夹”不存在。 So on the file loop
所以在文件循环上
file1 is renamed as E/New Folder (at this point file1 doesnt exist and its contents are in E/New Folder) file1 重命名为 E/New Folder(此时 file1 不存在,其内容在 E/New Folder 中)
file2 overwrites E/New Folder (file2 is removed and E/New Folder now has the contents of file2 and file1 contents are lost completely now) file2 覆盖 E/New Folder(file2 被删除,E/New Folder 现在有 file2 的内容,file1 的内容现在完全丢失)
file3 overwrites E/New Folder (file3 is removed and E/New Folder now has the contents of file3 and file2 contents are lost completely now) file3 覆盖 E/New Folder(file3 被删除,E/New Folder 现在有 file3 的内容,file2 的内容现在完全丢失)
file4 overwrites E/New Folder (file4 is removed and E/New Folder now has the contents of file4 and file3 contents are lost completely now) file4 覆盖 E/New Folder(file4 被删除,E/New Folder 现在有 file4 的内容,file3 的内容现在完全丢失)
file5 overwrites E/New Folder (file5 is removed and E/New Folder now has the contents of file5 and file4 contents are lost completely now) file5 覆盖 E/New Folder(file5 被删除,E/New Folder 现在有 file5 的内容,file4 的内容现在完全丢失)
So chances are E/New Folder is indeed a file and will hold the contents of the list file that went through shutil.move to this destination and all other files and contents are lost.所以很有可能 E/New Folder 确实是一个文件,它将保存通过 shutil.move 到此目的地的列表文件的内容,并且所有其他文件和内容都将丢失。
你的路径应该是C:/Users/Mahum/Downloads
而不是C/Users/Mahum/Downloads
If you didn't create the new folder before you moved the files it may have treated the request as a file and overwritten ontop of each other.如果您在移动文件之前没有创建新文件夹,它可能会将请求视为文件并相互覆盖。 Another thing that may have ocurred it just overwitten ontop of each file.
可能发生的另一件事只是覆盖在每个文件之上。 If you didn't have a back up you may have lost the files.
如果您没有备份,您可能已经丢失了文件。 You can try to recover with a disk recovery program.
您可以尝试使用磁盘恢复程序进行恢复。 Look for one for OS.
为操作系统寻找一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.