shutil.move deleted all my photos

百般思念 提交于 2019-12-10 12:24:37

问题


for i in os.listdir():
   if "jpeg" in i or "png" in i:
      shutil.move(os.path.join(os.getcwd(),i),"my photos")

I wanted to move all photos to a folder called "my photos" which is not exist. It created a txt file called "my photos" but it is just 300 kb and when I quickview it it only shows one of my photo. So how can I get my photos back? where are they now?


回答1:


I believe shutil.move simply took each file and interpreted "my photos" as the name to save each file as rather than a directory to copy it into. For each image in the directory, it would have overwritten it, leaving "my photos" with just the contents of the last image copied.

Looking at examples like this of how people have used shutil for moving files, they join the base directory name and the file name to form the target parameter.

I hope you had backups.



来源:https://stackoverflow.com/questions/41637906/shutil-move-deleted-all-my-photos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!