Previously, I wrote a script to automatically decompress the compressed file to the folder where the compressed file is located.
And then write the other two according to your needs. Same principle
Both use WinRAR commands
The first script is not considerate. You can only decompress the rarfile.
Improved support for various files supported by WinRAR
Save the files in the specified folder to the specified folder.
# Rardir. PY <br/> Import OS <br/> Import sys </P> <p> src = sys. argv [1] <br/> DST = sys. argv [2] </P> <p> Format = ['rar ', 'zip', '7z', 'acs', 'arj', 'bz2 ', 'cab ', 'gz', 'iso ', 'jar', 'lzh', 'tar ', 'uue ', 'Z'] </P> <p> OS. chdir (sys. argv [1]) <br/> for file in OS. listdir ('. '): <br/> If OS. path. isfile (File) and (OS. path. splitext (File) [1] [1:]. lower () in format) = true: <br/> # cmd = 'winrar X-ibck "'+ file +'" '+ DST +' // '+ OS. path. splitext (file) [0] + '// "' <br/> cmd = 'winrar X-ibck" '+ file +' "'+ DST +' //" '<br/> OS. system (CMD) <br/> OS. remove (File) <br/> Print ('done' + file)
Improvement of the first version
# Rardecmp. PY <br/> # decompress with WinRAR <br/> # arguments: filename directory opt <br/> # opt = 'mkdir' to create directory with the correspond filename <br/> # opt = 'direct' to decompress RAR files in current directory <br/> # opt = 'mk & del 'to mkdir and delete RAR file <br/> Import OS <br/> Import sys <br/> If Len (sys. argv )! = 3: <br/> Print ('wrong arguments/N') <br/> Print ('rar. PY directory opt/N') <br/> Print ('opt =/'mkdir/'to create directory with the correspond filename/N ') <br/> Print ('opt =/'direct/'to decompress RAR files in current directory/N ') <br/> Print ('opt =/'del del/'to decompress RAR files in current directory and delete files/N ') <br/> Print ('opt =/'mkdel/'to mkdir and delete RAR file/N') <br/> exit (0) </P> <p> #-ibck, minimized when running <br/> opt = sys. argv [2] <br/> OS. chdir (sys. argv [1]) </P> <p> Format = ['rar ', 'zip', '7z', 'acs', 'arj', 'bz2 ', 'cab ', 'gz', 'iso ', 'jar', 'lzh', 'tar ', 'uue ', 'Z'] </P> <p> for file in OS. listdir ('. '): <br/> If OS. path. isfile (File) and (OS. path. splitext (File) [1] [1:]. lower () in format) = true: <br/> If opt = 'mkdir ': <br/> cmd = 'winrar X-ibck "'+ file +'" '+' "'+ OS. path. splitext (File) [0] + '"//' <br/> OS. system (CMD) <br/> Elif opt = 'direct ': <br/> cmd = 'winrar X-ibck "'+ file +'" '<br/> OS. system (CMD) <br/> Elif opt = 'direcdel ': <br/> cmd = 'winrar X-ibck "'+ file +'" '<br/> OS. system (CMD) <br/> OS. remove (File) <br/> Elif opt = 'mkdel ': <br/> cmd = 'winrar X-ibck "'+ file +'" '+' "'+ OS. path. splitext (File) [0] + '"//' <br/> OS. system (CMD) <br/> OS. remove (File) <br/> else: <br/> Print ('wrong option') </P> <p>