auto updater of new releases

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
shokarta
Posts: 19
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: 4678
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: 19
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: 4678
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: 19
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!

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

Re: auto updater of new releases

#6 Post by shokarta » 27 Jul 2020 01:05

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:
set "release_path=\\username:password@some_remote_location\direktory\terminal.exe"

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

Re: auto updater of new releases

#7 Post by aGerman » 03 Aug 2020 14:11

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:
set "release_path=\\username:password@some_remote_location\direktory\terminal.exe"
You could map a network drive using NET USE. Refer to
https://docs.microsoft.com/en-us/previo ... 5(v=ws.11)

Steffen

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

Re: auto updater of new releases

#8 Post by shokarta » 20 Aug 2020 00:09

Hello Steffen,

would you mind if I kindly ask you to implement it into the initial batch script from you so its all together checked by you?
If I would do it, most likely there would be some unlogical syntax issue and I would be caming back to you few times before it would be working :(

Thank you for the best support

AdamsLor
Posts: 1
Joined: 20 Aug 2020 08:45

Re: auto updater of new releases

#9 Post by AdamsLor » 20 Aug 2020 08:54

aGerman wrote:
03 Aug 2020 14:11
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:
set "release_path=\\username:password@some_remote_location\direktory\terminal.exe"
You could map a network drive using NET USE. Refer to
https://docs.microsoft.com/en-us/previo ... 5(v=ws.11)

Steffen
I can't log in to this link!?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: auto updater of new releases

#10 Post by ShadowThief » 20 Aug 2020 13:48

You shouldn't have to log into it at all, but it's the same content as https://ss64.com/nt/net-use.html

Post Reply