zip_thumb How many times in a day do you download zip files and decompress them within some other directory ? As for me a dozen times a day.

So I need to automate the process:

1. Read the zip url from the clipboard
2. Download the zip file to a target directory I can choose BEFORE downloading (this gets me on my nerve to wait the end of download to be able to select the directory !)
3. Unzip the downloaded file
4. Open the directory and select the file in Windows Explorer

Here’s the code, explanation follows:


Rebol [
  title: "Automate zip download and decompression"
  author: "http://reboltutorial.com/blog/automate-zip-download/"
  version: 1.0.0
]

do http://reboltutorial.com/source/file-lib.r
do http://reboltutorial.com/source/zip-lib.r

download-directory: request-dir
file-url: to-url read clipboard://

file-short-name: file-name? file-url
file-extension: file-extension? file-url
binary-filename: rejoin [file-short-name file-extension]

binary-file-url: file-url
full-binary-path: rejoin [to-local-file  download-directory "" binary-filename]
full-binary-path: replace/all full-binary-path "" ""
full-binary-path: to-rebol-file full-binary-path

Print ["Downloading " file-url "..."]
Print ["... To " to-local-file full-binary-path " ..."]
write/binary full-binary-path read/binary binary-file-url
Print "... The End!"

Call rejoin ["explorer /select," {"} to-local-file full-binary-path {"}]

unzip %. full-binary-path

Download Directory must pre-exist otherwise the program will stop with an error (it is possible to create the directory automatically but let’s keep things simple at the moment).

If you’re too lazy, instead of writing and testing the code on your local pc, you can execute the code remotely as explained here by executing the instruction:


do http://reboltutorial.com/source/download.r

request-dir shows the dialog window asking for a directory.

Usage:

First copy the link to the clipboad BEFORE execution.

After execution, the directory dialog will show up:

Select a directory and wait until the file explorer opens selecting your zip file. The program will continue decompressing the file.

Bookmark and Share

Recent Articles