auto updater of new releases

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
shokarta
Posts: 8
Joined: 14 Oct 2012 05:54

auto updater of new releases

#1 Post by shokarta » 30 Mar 2019 09:48

Hello guys,

first I have to appologize, I have zero experience with batch scripting, however it look similar to other languages...

I would like to kindly ask for your help developing a very simple couple row script, whic basicaly should do:

1) check the directory (for example C:/Terminal/NewReleases/) and go through every exe files in that directory
2) in case there is newer (compare by date) exe file in that directory in compare to C:/Terminal/terminal.exe then copy the newer file (whatever its named) to C:/Terminal/ and overwrite to terminal.exe
3) once its done, just run terminal.exe

Note: this bat file will be located in C:/Terminal, therefore maybe dont refer to absolute directory (C:/Terminal) but instead recall somehow CURRENTDIRECTORY
Howver the C:/Terminal/NewReleases is just an exmpale of the folder, it can change anytime to some network remote harddrive, therefore this path should stay as absolute...
So if the directory to check for new releases is not available, then just skip and run the terminal.exe from C:/Terminal

Thank oyu guys!

aGerman
Expert
Posts: 3625
Joined: 22 Jan 2010 18:01
Location: Germany

Re: auto updater of new releases

#2 Post by aGerman » 31 Mar 2019 08:49

The date format is dependent on local settings. In order to be able to compare it, we need to know how it looks like on your computer.
Create a batch file with the following line only.

Code: Select all

@echo "%~t0"|clip
Run it once. Date and time of the batch script will be copied to the clipboard. Paste it into your next reply.

Steffen

shokarta
Posts: 8
Joined: 14 Oct 2012 05:54

Re: auto updater of new releases

#3 Post by shokarta » 31 Mar 2019 09:53

"31.03.2019 17:52"

aGerman
Expert
Posts: 3625
Joined: 22 Jan 2010 18:01
Location: Germany

Re: auto updater of new releases

#4 Post by aGerman » 31 Mar 2019 10:55

Give that a go.

Code: Select all

@echo off &setlocal

set "release_path=C:\Terminal\NewReleases"
set "file_name=terminal.exe"

pushd "%release_path%"
for %%i in ("%~dp0%file_name%") do for /f "tokens=1-5 delims=.: " %%j in ("%%~ti") do set "current_time=%%l%%k%%j%%m%%n"
for /f "delims=" %%i in ('dir /a-d /b /od *.exe') do (set "recent_time=%%~ti"&set "recent_file=%%~i")
for /f "tokens=1-5 delims=.: " %%j in ("%recent_time%") do set "recent_time=%%l%%k%%j%%m%%n"
if "%recent_time%" gtr "%current_time%" copy /y "%recent_file%" "%~dp0%file_name%"
popd

start "" "%file_name%"
To avoid problems remember that paths on Windows are separated with backward slashes instead of forward slashes.

Steffen

shokarta
Posts: 8
Joined: 14 Oct 2012 05:54

Re: auto updater of new releases

#5 Post by shokarta » 31 Mar 2019 22:24

works like a charm!

many thanks!

Post Reply