0

I have a script on Jupyter Notebook that unzip files, create directories, and move the unzipped files to these directories. However, the script only works in *nix operating systems.

# the name of your folder where the LIEF files are
lief_data_folder = 'Images' 

# Is the Account Multi-store? (True/False)
is_multi_store = False

# set the path
base_path = os.getcwd()
raw_data = base_path+'/'+lief_data_folder

# unzip and move file
os.chdir(raw_data)
!for z in *.zip; do unzip -d _$z -o "$z"; done
!mkdir 'products'
!for item in _product_2020*;do mv -f $item 'products'; done
!mkdir 'products_photo'
!for item in _product_photo_*;do mv -f $item 'products_photo'; done
!mkdir 'raw_zip'
!for item in *.lief-packet.zip;do mv -f $item 'raw_zip'; done
!mv 'Data Export Log' 'raw_zip'
!mv 'Data Export Summary' 'raw_zip'
os.chdir(base_path)

print('DONE')

I know that mv is move in Windows but what's the equivalent of unzip or a better solution for Windows? Also what are the equivalent of the options above in mv?

Damph98
  • 1
  • 1
  • Please take a look at the following threads: [How to move a file?](https://stackoverflow.com/questions/8858008/how-to-move-a-file) [Unzipping files in Python](https://stackoverflow.com/questions/3451111/unzipping-files-in-python) – metatoaster Jan 21 '21 at 03:45
  • python has module `zipfile` to zip/unzip files. You may also install `zip` like in Linux using [unzip](http://gnuwin32.sourceforge.net/packages/unzip.htm) from [GnuWin32](http://gnuwin32.sourceforge.net/packages.html). There are also other programs - ie. `mv`, `ls`, `mkdir` in [CoreUtils](http://gnuwin32.sourceforge.net/packages/coreutils.htm) in `GnuWin32`. OR you may try [Windows Subsystem for Linux](https://ubuntu.com/wsl) – furas Jan 21 '21 at 05:01

1 Answers1

0

Python has module zipfile to zip/unzip files. And shutil.unpack_archive() for zip, tar, etc.

You may also install zip like in Linux using unzip from GnuWin32.

There are also other useful programs in GnuWin32 - ie. mv, ls, mkdir in CoreUtils.

Or you may try Windows Subsystem for Linux and you will have Linux terminal in Windows.


I use Linux and I can't say how works WSL but long time ago when I was using Windows
then I always was using tools from GnuWin32

furas
  • 134,197
  • 12
  • 106
  • 148