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 ?

  • 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

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!
    wget http://server6.mp3quran.net/abkr/!num!.mp3

Edit 1: Removed unnecessary braces.

Edit 2: Corrected counter start value to 1.

  • 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

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

wget http://server6.mp3quran.net/abkr/{001..114}.mp3

A solution that should work with any shell:

for i in $(seq -w 1 114); do
    printf 'http://server6.mp3quran.net/abkr/%s.mp3 ' $i
done | xargs wget

or, if seq does not exist on the system:

while [ $i -le $MAX ]; do
    printf 'http://server6.mp3quran.net/abkr/%03d.mp3 ' $i
done | xargs wget

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

  • 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

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("http://server6.mp3quran.net/abkr/" + $file, $file)

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


For reference and the sake of completeness a version without seq, a nice output and continue if the download stops for whatever reason:

for i in 00{1..9} 0{10..99} {100..144}; do
    printf 'http://server6.mp3quran.net/abkr/%03d.mp3 ' $i
done | xargs wget -q --show-progress -c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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