'Need to remove a particular file of size 0 from a directory
Need to remove a particular file of size 0 from directory, can anyone help me on that?
The code i have tried is
for f in source_images:
file_path = os.path.join(SOURCE_DIR,f)
size = os.path.getsize(file_path)
if size == 0:
print(f'{f} is zero length, so ignoring')
os.remove(file_path)
The error i am getting afterwards is below
/usr/lib/python3.7/shutil.py in copyfile(src, dst, follow_symlinks)
118 os.symlink(os.readlink(src), dst)
119 else:
--> 120 with open(src, 'rb') as fsrc:
121 with open(dst, 'wb') as fdst:
122 copyfileobj(fsrc, fdst)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/PetImages/Dog/11702.jpg'
Any suggestion to overcome this!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
