2

I need to do a script for download images resursive, How can i do it. I am on a Windows.

I want something like this:

for(int i = 0 ; i < 100; i++) {
   wget "http://download/img" + i + ".png
}

How can i do this with a Windows Batch script?

Raxkin
  • 387
  • 1
  • 3
  • 18
  • http://stackoverflow.com/questions/4602153/how-do-i-use-wget-to-download-all-images-into-a-single-folder – gurkan May 11 '15 at 20:54
  • i dont want to download all the images, i only need to download images on a range – Raxkin May 11 '15 at 20:56
  • If you have any pattern, ‘reject-regex = urlregex’ or ‘accept-regex = urlregex’ can be used like in http://www.gnu.org/software/wget/manual/wget.html#Recursive-Download . – gurkan May 11 '15 at 21:03

2 Answers2

3

The Windows equivalent to that sort of for loop is for /L. Syntax is

for /L %%I in (start,step,finish) do (stuff)

See help for in a console window for more info. Also, Windows batch variables are evaluated inline. No need to break out of your quotes.

for /L %%I in (0,1,100) do (
    wget "http://download/img%%I.png"
)

... will download img0.png through img100.png with no numeric padding.

If the numbers are zero padded, there's an added element to consider -- delayed expansion. Within a for loop, variables are evaluated before the for loop loops. Delaying expansion causes the variables to wait until each iteration to be evaluated. So, zero padding then taking the right-most 3 characters requires something like this:

setlocal enabledelayedexpansion
for /L %%I in (0,1,100) do (
    set "idx=00%%I"
    wget "http://download/img!idx:~-3!.png"
)

... which will download img000.png through img100.png.

rojo
  • 24,000
  • 5
  • 55
  • 101
0

There are some parameters that can be used with wget including a recursive mode and also extension filter.

Please have a look at here

Community
  • 1
  • 1
gurkan
  • 3,457
  • 4
  • 25
  • 38