Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Help Needed in Batch Script

25 Feb 2015   #1
born2achieve

windows7 64 bit
 
 
Help Needed in Batch Script

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 System SpecsSystem Spec
.
25 Feb 2015   #2
edy1en

Windows 7 Ultimate x64
 
 

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 System SpecsSystem Spec
26 Feb 2015   #3
SIW2

Microsoft Community Contributor Award Recipient

Vista x64 / 7 X64
 
 

You can use wget -p to specify destination.

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 System SpecsSystem Spec
.

26 Feb 2015   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 System SpecsSystem Spec
26 Feb 2015   #5
born2achieve

windows7 64 bit
 
 

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 System SpecsSystem Spec
Reply

 Help Needed in Batch Script




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
W10 TP : Old Windows Update Batch/Script
Hi, I need you for obtain a batch for apply this custom : Retrouvez votre bon vieux Windows Update sous Windows 10 - Le comptoir du hardware Can you help me ? Thanks Have a good day !
Windows Updates & Activation
How to run cmd.exe elevated in batch script
Hi All, I am writing a dos batch file for windows7 and it has many commands which need elevated access to run. For elevation I am using elevate.exe. I am doing like below - set Elevation=elevate -wait cmd.exe /c %Elevation% "cd /d %CD% && xcopy /E /Y ...." %Elevation% "cd /d %CD% &&...
General Discussion
batch script help
dear all any help to make batch script this the reason i want to make a batch file is to help me update the online games in 60 computers by overwriting or copying big files in one click from 1 source computer... instead of turning on all 60 computers and updating all online games, he'll just...
General Discussion
Problem with echo in batch script
Morning i have a problem with batch script in Windows 7. this is my code: @echo off set mypath=c:\tools if not exist "%mypath%\architet.txt" goto check3264 find /I "x64-based PC" "%mypath%\architet.txt" >nul 2>&1 if %errorlevel% EQU 0 (set architet=64) ELSE (set architet=32) goto uacok...
General Discussion
Help me with Batch script!
Hi, Can somebody assist me with a .bat file I am trying to create? This is what I have now: start /d "C:\Users\Me\Desktop\ghost" ghost.exe start /d "C:\Users\Me\Desktop" Poweroff.exe C:\Windows\System32\powercfg.exe /setactive e428f8a5-615e-488f-b7f7-1ed39450e522The first 2 lines start...
Software


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 17:04.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App