4 Dec 2009

Combining DOS commands just like you do on UNIX

UNIX/Linux command line is such an interesting thing to play with. Unix Command line users have always been able to combine (more correctly called - chain or pipeline) commands. But did you know this was also possible in the DOS command line?

1 Dec 2009

Command line Kung Fu!

Came across this post about command scripts to bulk download wallpapers from the National Geographic website.

The script for Windows using is 20 lines long and this is just the first one to download the ones for 2008. That totals to 40 lines in two scripts (one for 2008 and the other for 2009).

x=MsgBox("Starting download of pictures.",0)


res="1024"


Set objShell = CreateObject("WScript.Shell")


For a = 1 to 26


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/1107wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/1103wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/1027wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/1020wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/1014wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/1006wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0929wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0922wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0915wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0908wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0901wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0825wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0818wallpaper-" & a & "_" & res & ".jpg""",0,true


        objShell.Run "wget -U Mozilla ""http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/0811wallpaper-" & a & "_" & res & ".jpg""",0,true


Next


x=MsgBox("Finished downloading pictures.",0)




I had an idea on doing the same thing in less than 40 lines. Here’s my result





@echo off


echo Starting download of pictures


 


:wall_2008


REM 2008 Wallpapers


set res=1024


for %%x in (1107,1103,1027,1020,1014,1006,0929,0922,0915,0908,0901,0825,0818,0811) DO curl -O http://ngm.nationalgeographic.com/photo-contest/img/wallpaper/%%xwallpaper-[1-26]_%res%.jpg


 


:wall_2009


REM 2009 Wallpapers


set res=1600


for %%x in (1109,1102,1026,1019,1013,1005,0928,0921,0914,0907,0831,0824,0817) DO curl -O http://ngm.nationalgeographic.com/photo-contest/2009/img/wallpaper/%%xwallpaper-[1-26]_%res%.jpg


 


echo Finished downloading pics




Total Number of lines = 14! Hurray! Oh and yes, the only change I made was to use my favourite cURL instead of wget to download the images.



To use my script, copy-paste my script into a file with the extension .BAT or .CMD (example: DownloadNGWallpaper.cmd), make sure you have cURL in your path and fire away! I have uploaded this script at pastebin in case copy-pasting it from above is a problem.



Questions, comments and improvements (of course!) welcome :-)