i'm trying to do a program here i need to compress some files, but i want it to stop when the file doesn't exist. The code works, but the thing is that it compresses the file anyway, what i mean is that the program outputs the error but compress a file with that name (an empty file)
if someone could help it would be wonderful :)
import sys, zipfile
def compress (file):
try:
zf = zipfile.ZipFile(file + '.zip', mode='w')
zf.write(file, compress_type=zipfile.ZIP_DEFLATED)
zf.close()
except OSError:
print("The file "+ file + " doesnt exist!")
#erro.value = 1
if __name__ == "__main__":
compress(sys.argv[1])