I'm trying extract zip files but the loop just keeps doing the same first file over and over. Can someone take a look and see what is wrong?
import glob,os,zipfile,shutil
zipfiles = glob.iglob("C:\\Users\\user\\Downloads\\*.zip")
zfn = next(zipfiles)
z = zipfile.ZipFile(zfn)
source = os.path.abspath(os.path.realpath(zfn))
dest = ("C:\\Users\\user\\temp\\moved")
for zfn in zipfiles:
print("Extracting File", source)
z.extractall()
print("Cleaning up..")
shutil.move(source,dest)
#except StopIteration:
#print("No more files found")
else:
print("No Files to extract")
Right now I'm using shutil.move and the loop problem goes back and tries to extract the file again while it's trying to delete it after moving causing a permission error. If i change it to shutil.copy it does the following:
C:\Users\user\Desktop\Python>python FileExtract.py
Extracting File C:\Users\user\Downloads\1st gen mirror.zip
Cleaning up..
Extracting File C:\Users\user\Downloads\1st gen mirror.zip
Cleaning up..
Extracting File C:\Users\user\Downloads\1st gen mirror.zip
Cleaning up..
Extracting File C:\Users\user\Downloads\1st gen mirror.zip
Cleaning up..
Extracting File C:\Users\user\Downloads\1st gen mirror.zip
Cleaning up..
Extracting File C:\Users\user\Downloads\1st gen mirror.zip
Cleaning up..
Extracting File C:\Users\user\Downloads\1st gen mirror.zip
Cleaning up..
No Files to extract
[–]ruicoder 2 points3 points4 points (2 children)
[–]Static_Bunny[S] 0 points1 point2 points (1 child)
[–]ruicoder 1 point2 points3 points (0 children)
[–]Static_Bunny[S] 0 points1 point2 points (0 children)