transitionality December 9, 2014 at 11:33:59 Specs: Windows XP, C2D 1.66 Ghz
I'd like a batch file to do the following:
* Read the expected file size of the target file (in bytes) from a save file. * Connect to the server hosting the target file and query its file size (in bytes). * If the two values match, quit. If they don't, download the target file to a specific local path (overwriting the current instance) and update the file size value in the save file.
I use curl for command-line downloading, but I can probably adapt solutions using other tools.
No "turn-key" solution, since I don't have CURL.exe that will execute on my system. I use WGET which has an option to "don't download anything" and gives me the file's size without having to download it. WGET is also recalcitrant in that it will not pipe out. It always reports directly to CONSOLE unless you invoke the alternate-output option. FWIW here's the wget version: @echo off & setlocal set target=VB40032 if not exist %target% ( wget pages.suddenlink.net/leeworkman/%target% goto :eof ) @echo off & setlocal for /f "tokens=2" %%a in ('curl -I pages.suddenlink.net/leeworkman/VB40032^|find /i "content-length:"') do set size=%%a ) echo size:%size% :: get local file's size from the directory entry for %%a in (%TARGET%) do set cmpare=%%~za echo local: %cmpare% -- server: %size% if %cmpare% neq %size% ( echo sized diff, downloading new: wget -O %target% pages.suddenlink.net/leeworkman/%target% ) ::===== END BATCHSCRIPT I saw no reason to store the local file's size, since it is most dependably obtained from the directory entry for the file.
na, don' worry bout it. I got cURL to work on my 7 (just neede msvcr110.dll renamed from msvcr110_clr0400.dll). I slogged through the options, and came up with this: ::===== begin batch snippet @echo off & setlocal for /f "tokens=2" %%a in ('curl -I pages.suddenlink.net/leeworkman/VB40032^|find /i "content-length:"') do set size=%%a ) ::========= end snip the rest is same from ":: get local file's size" on down.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this
site. Computing.Net and Purch hereby disclaim all responsibility
and liability for the content of Computing.Net and its accuracy.