Help Needed in Batch Script

born2achieve

New member
Local time
8:45 AM
Messages
36
Hi,

I have 1000 image url in my text file(sample.txt) and i want to download the images using the url. Can anyone please share with me the sample script which can do this in single shot.

Also, is there any way to reduce the size of the image into 20/20 px with png extension.

Thanks
 

My Computer

Computer type
PC/Desktop
OS
windows7 64 bit
hmmm im not very good with batch... but you can do this with wget.
your txt content is

Code:
www.pic.com/pic01.jpg
www.pic.com/pic02.jpg
right?

then get wget and use this command
wget -i sample.txt

and for resizing, get irfanview and use batch resize function.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
CUSTOM
OS
Windows 7 Ultimate x64
CPU
Q6600
Motherboard
Gigabyte EP45 DS3R
Memory
8 GB mixed brand
Graphics Card(s)
Colorful GT260 216 sp
Hard Drives
7TB total
Antivirus
Baidu AV 2015
Browser
Waterfox, Firefox, Chrome, Opera
You can use wget -p to specify destination.

View attachment WGET.zip

This batch file will download them into a folder called DESTINATION

e.g.

Code:
@echo off
SET TP=%~dp0
SET TP=%TP:~0,-1%
cd /d "%TP%"
mode con lines=40 cols=100
color 5f
  for /F "delims=" %%A in (MYURLS.txt) do (
       wget -P DESTINATION/ %%A
  )
 PAUSE
 

My Computers

System One System Two

  • Computer type
    PC/Desktop
    OS
    7 X64
    CPU
    i5 8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Hard Drives
    various
    PSU
    pure power 11 400w cm
    Case
    Coolermaster
    Cooling
    cryorig m9i
  • Computer type
    PC/Desktop
    OS
    7x64
    CPU
    g5400
    Motherboard
    ga b365m ds3h
    Memory
    8gb ddr4 2400
    PSU
    xfx pro 450w
Hi Born2achieve,

As you might now know--the command prompt, or batch files for that matter, cannot download web files without the need of a third party application.

If you're okay with downloading and using Wget, SIW2's batch script works... beautify.

Else if not, here is a PowerShell script you may use that will get the job done.

DownloadImagesFromTxtList.ps1
Code:
# Duplicate items in the destination directory will be overwritten.

# Edit below values
$url_list = "C:\Path\to\myurls.txt"
$local_output_dir = "C:\Some\destination\folder"
#

$WebClient = New-Object System.Net.WebClient

if ( (Test-Path $local_output_dir) -eq $false ) {
    'Error: The destination folder does not exist.'
    exit 1
}

try {
    $fh = [IO.File]::OpenText( $url_list )
}
catch [System.Management.Automation.MethodInvocationException] {
    'Error: The file "' + $url_list + '" could not be found.'
    exit 1
}

try {
    for (;;) {
        $line = $fh.ReadLine()
        ## Read-Host > $null # A pause statement
        if ( $line -eq $null ) { break }
        
        if (!( $line -match "^https?://.*$" )) { $line = 'https://' + $line }
        $line = [URI]$line
        
        'Downloading "' + $line.OriginalString + '"...'
        $WebClient.DownloadFile( $line.OriginalString, (Join-Path -Path $local_output_dir -ChildPath $line.Segments[-1]) )
        'Saved "' + $line.OriginalString + '" to "' + (Join-Path -Path $local_output_dir -ChildPath $line.Segments[-1]) + '"'
        
        ''
    }
}
finally {
    $fh.Close()
}
'Done.'

However, a few things must be configured prior to executing PowerShell scripts. A tutorial for running PowerShell scripts does not yet exist on this forum's tutorial index, so you're going to have to figure that one out.

Also, there is a thing you should know, Born2achieve, about both the Batch and PowerShell script solutions: if a web file specified in the text file of URLs happens to not exist, the file will be downloaded anyway. So the result will not always end up being a proper functioning image.
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Thank you Pyprohly for the great tip. I will try with the PowerShell and let you know. honestly i ever used PowerShell in my experience. It's new to me. but i wanted to give a try. Will postback to you once i am done.

Thanks for your time and thanks everyone who tried to help me on on this post.
 

My Computer

Computer type
PC/Desktop
OS
windows7 64 bit
Back
Top