shutil.move deleted all my photos

2019-06-09 18:04发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-06-09 18:13

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.

查看更多
登录 后发表回答