Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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..

http://server6.mp3quran.net/abkr/001.mp3
http://server6.mp3quran.net/abkr/002.mp3
...
http://server6.mp3quran.net/abkr/113.mp3
http://server6.mp3quran.net/abkr/114.mp3

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
add comment

3 Answers

up vote 2 down vote accepted

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

@ECHO OFF
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
)
EndLocal

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
add comment

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:

#!/bin/sh
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:

#!/bin/sh
i=1
MAX=114
while [ $i -le $MAX ]; do
    printf 'http://server6.mp3quran.net/abkr/%03d.mp3 ' $i
    i=$((i+1))
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.