auto updater of new releases

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
shokarta
Posts: 9
Joined: 14 Oct 2012 05:54

auto updater of new releases

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: 3895
Joined: 22 Jan 2010 18:01
Location: Germany

Re: auto updater of new releases

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: 9
Joined: 14 Oct 2012 05:54

Re: auto updater of new releases

"31.03.2019 17:52"

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

Re: auto updater of new releases

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: 9
Joined: 14 Oct 2012 05:54

Re: auto updater of new releases

works like a charm!

many thanks!

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

Re: auto updater of new releases

Hello,

i know this is quite a long time,
But I have found, that if the file terminal.exe doesnt exist, all script stops on this…

Is it posisble to modify to check if the file localy exists, and if not then jsut download the file from the remote directory?

+ also, would be possible to add credential check?
for some remote folders where security allows only some users, i have the error of "Invalid username or password" and when opening the dir in explorer the Windows pops up the credentials window.
- so would be possible to open the directory with credentials?

maybe something like:

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

Re: auto updater of new releases

shokarta wrote:
27 Jul 2020 01:05
Is it posisble to modify to check if the file localy exists, and if not ...
Something like

Code: Select all

if not exist "c:\foo\bar.exe" ...
then jsut download the file from the remote directory?
The second FOR loop defines variable recent_file that you should use to copy the file then.
+ also, would be possible to add credential check?
for some remote folders where security allows only some users, i have the error of "Invalid username or password" and when opening the dir in explorer the Windows pops up the credentials window.
- so would be possible to open the directory with credentials?

maybe something like: