Home > other >  Turn to the great god how to compress multiple files into multiple compression package
Turn to the great god how to compress multiple files into multiple compression package

Time:11-28

If 50 files are there in a folder, now want to python the 50 each single compressed into a zip file, namely each compression bag 1 file, a total of 50 package, help the great spirit guide code

CodePudding user response:

Try it,,,

 
the import the OSThe import zipfile

Flist=OS. Listdir (')
For I in flist:
Fpath=OS. Path. Join ('. ', I)
Fzip=zipfile. Zipfile (I + 'zip', 'w', zipfile. ZIP_DEFLATED)
Fzip. Write (fpath)

CodePudding user response:

Is probably so, change your winrar directory,

 
The import OS

50 # traversal folder name to file_list
For file_name in file_list:
Run_cmd="'" C: \ Program Files \ WinRAR \ WinRAR exe "{0}." rar {0} ' ' '. The format (filename)
OS. The system (run_cmd)
  • Related