Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a case that I would like to trigger an automatic download for a list of 114 file (recitation) for each reader,
for example if i want to download the recitations for a reader called abkr, the urls for the files will look like the following..

simply these are Quran recitations, so they are always have a total of 114

is there an easy way to loop that using command line on Windows ?

share|improve this question
Which operating system? – Indrek Sep 3 '12 at 13:16
Windows is preferred, Mac is Ok as well.. – Anas Nakawa Sep 3 '12 at 14:18
up vote 4 down vote accepted

For the sake of completeness, here's a batch-only solution:

SetLocal EnableDelayedExpansion
FOR /L %%G IN (1, 1, 114) DO (
    SET num=%%G
    IF 1!num! LSS 100 SET num=0!num!
    IF 1!num! LSS 200 SET num=0!num!

Edit 1: Removed unnecessary braces.

Edit 2: Corrected counter start value to 1.

share|improve this answer
all solutions are great, but I'm gonna accept this since it is straight forward (command-prompt), and does not require something other than wget.. – Anas Nakawa Sep 5 '12 at 5:31
a small correction, the loop starts from 1 instead of 0. – Anas Nakawa Sep 5 '12 at 5:32
Oops, correcting... – zb226 Sep 5 '12 at 8:09

For a Windows solution, try the following PowerShell script:

$Client = New-Object System.Net.WebClient
for ($i = 1; $i -le 144; $i++)
    $file = [string]::Format("{0:D3}.mp3", $i)
    $Client.DownloadFile("" + $file, $file)

First cd into the directory you want to download the files to, of course.

share|improve this answer

You haven't stated OS, but if you are using *nix and Bash the following works:


A solution that should work with any shell:

for i in $(seq -w 1 114); do
    printf ' ' $i
done | xargs wget

or, if seq does not exist on the system:

while [ $i -le $MAX ]; do
    printf ' ' $i
done | xargs wget

Just copy+paste it in the shell or save it in a script file and run it.

share|improve this answer
is Mac OSX included in your *nix solution ? – Anas Nakawa Sep 4 '12 at 4:15
anasnakawa: Yes, you can run Bash on MacOSX, but it is not the default shell, I believe. Try just running the command "bash" in a terminal. You might need to install it beforehand, or look for a simple solution using the default shell. To clarify: the above will definitely work, but it might not be the most obvious way if Bash is not already installed. – Daniel Andersson Sep 4 '12 at 8:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.