Automatic download by bat - View file date before download

Asked

Viewed 2,019 times

2

I want to create a script at windows prompt to update the system automatically. But I only want to download if you have new update. Could anyone tell me how I could check the file date (.rar) before downloading ? Otherwise, I download and then check the date...

Thank you.

  • Where is the RAR file?

  • In a direct download link.

2 answers

2



  • Just see the file date getting last modification:`
cUrl.exe -# -I https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar |find "Last-Modified"

  • output:
Last-Modified: Tue, 15 Dec 2009 09:50:15 GMT

  • The two tasks of checking and downloading in a command: Wget -N or Curl -Z --time-cond

If you consider making use of some external tool to do, checking and downloading your update not using a VBS.script Powershell or C#, for checking dates between local/remote files, I suggest trying with the Wget.exe and/or the cUrl.exe.


  • Both the cUlr.exe and the Wget.exe, bring the support to check the dates between the archival and the archvos_remotos, where it is possible to download the latest file (updating)...

  • With the use of Wget.exe, you could try the following command:
@echo off && setlocal enabledelayedexpansion & cd /d "%~dp0"

set "_arq_rar=G:\SO_pt-BR\Q407637\WinRAR_Noia_Bogart_64x64.theme.rar"
set "_link_rar=https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar

Wget.exe -N "!_arq_rar!" "!_link_rar!"

The Wget.exe -N will instruct the Wget.exe to only download the file when the remote is newer than the local file pointed in the command.

  • The local file must pre-exist to make this comparison...

  • With the use of cUrl.exe, you could try the following command:
@echo off && setlocal enabledelayedexpansion & cd /d "%~dp0"

set "_arq_rar=G:\SO_pt-BR\Q407637\WinRAR_Noia_Bogart_64x64.theme.rar"
set "_link_rar=https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar

cUrl -Z --time-cond "!_arq_rar!" "!_link_rar!" --output "!_arq_rar!"

The Curl.exe -Z --time-cond "! _arq_rar!" will instruct the curl.exe to compare the date of the local file pointed in the command, with the date of the remote file present in the link, so if the remote file is newer, then it will download to the user.

  • The local file must pre-exist to make this comparison...

  • Links Wget.exe 32/64bit:

Wget.exe 64-Bit:

https://eternallybored.org/misc/wget/1.20.3/64/wget.exe

Wget.exe 32-Bit:

https://eternallybored.org/misc/wget/1.20.3/32/wget.exe

Documentation: https://www.gnu.org/software/wget/manual/

  • Links Curl.exe 32/64bit:

Curl.exe 64-Bit:

https://curl.haxx.se/windows/dl-7.66.0_2/curl-7.66.0_2-win64-mingw.zip

Curl.exe 32-Bit:

https://curl.haxx.se/windows/dl-7.66.0_2/curl-7.66.0_2-win32-mingw.zip

Documentation: https://curl.haxx.se/docs/manpage.html


The above suggestions consider that the executables were added in the same folder as the cmd/bat file and it is the same folder where you will save the files, otherwise add a variable that points to the executable folder, getting:

  • For use with Wget in another folder:

@echo off && setlocal enabledelayedexpansion & cd /d "%~dp0"

rem :: se usar o wget.exe ::
set "_wget=c:\pasta_do_Wget"

set "_arq_rar=G:\SO_pt-BR\Q407637\WinRAR_Noia_Bogart_64x64.theme.rar"
set "_link_rar=https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar

pushd "!_Wget!" & Wget.exe -N "!_link_rar!" & popd

  • For use with Curl in another folder:

@echo off && setlocal enabledelayedexpansion & cd /d "%~dp0"

rem :: se usar o cUrl.exe ::
set "_cUrl=c:\pasta_do_curl"

set "_arq_rar=G:\SO_pt-BR\Q407637\WinRAR_Noia_Bogart_64x64.theme.rar"
set "_link_rar=https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar

pushd "!_cUrl!" & cUrl.exe -Z --time-cond "!_arq_rar!" "!_link_rar!" --output "!_arq_rar!" & popd

For your test, edit the relevant variables:


rem :: caso use o Wget.exe ::
set "_Wget=c:\pasta_do_Wget"

:: ou ::
rem :: caso use o cUrl.exe ::
set "_cUrl=c:\pasta_do_cUrl"

set "_arq_rar=G:\SO_pt-BR\Q407637\WinRAR_Noia_Bogart_64x64.theme.rar"
set "_link_rar=https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar


To view the date before downloading and saving in a variable:


rem :: Usando cUrl.exe ::
for /f tokens^=2delims^=^>: %i in ('curl -s -v -X HEAD https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar 2^>^&1 ^| find "-modified"')do (set "_dtmod=%i" & cmd /v/c echo/%i)

rem :: Usando Wget.exe ::
for /f ^tokens^=2*delims^=: %i in ('wget --server-response --spider "https://www.rarlab.com/themes/WinRAR_Noia_Bogart_64x64.theme.rar" ^2^>^&1 ^| find /i "modified"')do (set "_dtmod=%i" & cmd/v/c echo/%i)

  • To work it is necessary that there is a local file, because it will check the dates between the remote file and the local file...

1

I don’t have a file link . rar to test more I’ll give you an example using a zip file and Curl tool:

curl -I https://www.macrorecorder.com/MacroRecorder_Portable.zip 2> Nul | find /i "last-modified"

This will result in something like: last-modified: Wed, 11 Sep 2019 15:18:29 GMT

The Curl tool is already included in the latest versions of Windows 10 and if not have just download.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.