Help Needed in Batch Script


  1. Posts : 36
    windows7 64 bit
       #1

    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 Computer


  2. Posts : 7
    Windows 7 Ultimate x64
       #2

    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


  3. Posts : 16,161
    7 X64
       #3

    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 Computers


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    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


  5. Posts : 36
    windows7 64 bit
    Thread Starter
       #5

    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


 

  Related Discussions
Our Sites
Site Links
About 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 06:53.
Find Us