Are you looking for my non-technical blog?

This is now my technical-only blog, my non-technical blog is here.

22 June 2007

Wget and DOS For Loop

Most of the time when you want to download a file, you righ-click on its URL in your browser and choose "Save Target As", to save it somewhere in your local hard drive. But imagine the case where you want to download about 100 files, saving each file individually will be really boring and time consuming. So let me first introduce you to a tool called "wget"

"GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP, the most widely-used Internet protocols. It is a non-interactive commandline tool, so it may easily be called from scripts", GNU Wget Page.

The good news here is that they have Windows binaries in order to run it on your Windows PC. Now, one more thing to mention is that you can write a simple "For" loop in DOS.

FOR %variable IN (set) DO command [command-parameters]

Let's say we want to download the Holy Quraan from Islam-Way website. Each Sura is stored in a separate file, and these files are named "001.mp3", "002.mp3", etc. And the files are all stored in the following location, "".

So, go to "Start Menu" and click on "Run", and write "cmd.exe" there and hit the "OK" button. Repeat this step three times in order to have three command prompt windows open. Then write the following commands in the open windows to download all the files. Now, make yourself a cup of coffee and grab a book and start reading it till your computer finishes downloading.

for /L %i in (1,1,9) do wget -O 00%i.mp3
for /L %i in (10,1,99) do wget -O 0%i.mp3
for /L %i in (100,1,114) do wget -O %i.mp3

Tags: , ,