Home > other >  How to use the python implementation of directory xz extract the compressed file?
How to use the python implementation of directory xz extract the compressed file?

Time:10-05

How to use the python implementation of directory xz extract the compressed file? Iterates through all xz compressed file directory, and then to extract the python statements?

CodePudding user response:

Probably code so, you want the xz unpack command to replace OS. The command in the system can,
 

The import OS
Def check_all_files (check_path, file_ext=' ') :
List_files=[]
# listed folder all directories and files
Cur_list=OS. Listdir (check_path)
For I in range (0, len (cur_list) :
File_path=OS. Path. Join (check_path, cur_list [I])
If OS. Path. Isdir (file_path) :
List_files. The extend (check_all_files (file_path file_ext))
If OS. Path. Isfile (file_path) :
If file_ext!=' ':
If file_path [len (file_ext) * 1:]==file_ext:
List_files. Append ([cur_list [I], file_path])
The else:
List_files. Append ([cur_list [I], file_path])
Return list_files



If __name__=="__main__" :
File_list=check_all_files (r 'F: \ data', 'xz)
For file in file_list:
Print (file [1])
Unzip OS. System (' {} '. The format (the file [1]))

  • Related