So today I had to fetch some images from the certain website and save them in the dynamically generated folders. The image names were easily constructed from the ordinal number of the image so i thought i should create a small PowerShell script. I had to go with the PowerShell because the plain batch (.bat) script does not support wget command out of the box.

The image names were in the form 001s.jpg… 012s.jpg .. 123s.jpg so i had to build the filename first (with leading zeroes), and the other catch was that they had to be saved in the directory that is constructed using their ordinal number (and created before the fetch), and filename had to be “thumb.jpg”.

for($i=1; $i -le 143;$i++){
 $url = ("{0}{1}{2}" -f "", $i.ToString("d3"), "s.jpg")
 $dirname = ("{0}{1}" -f "C:\Users\yourusername\thumbs\thumbfolder ",$i.ToString())
 $dest = ("{0}{1}{2}" -f $dirname,"\","thumb.jpg")
 mkdir $dirname
 wget $url -OutFile $dest

Hope it helps,



Leave a Reply

Your email address will not be published. Required fields are marked *