Update.cmd code suggestion

Update.cmd code suggestion

Postby gentoouser » 12.07.2017, 17:23

I have updated the Update.cmd to be more portable please consider updating the master repository with the changes below:

Code: Select all
@echo off
title Installing updates . . .
Set LaunchPath=%~dp0
If "%LaunchPath:~-1%" == "\" (
  Set LaunchPath=%LaunchPath:~0,-1%
REM Find Free Drive
REM Looping code from: https://ss64.org/viewtopic.php?pid=3657
Set Drives=Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
set TN=1


set MapDrive=
for /f "tokens=%TN% " %%i in ("%Drives%") do (
    set MapDrive=%%i
:: double quotes are important here, because string parts may contain spaces!
If "%MapDrive%" neq "" (
 If NOT EXIST "%MapDrive%:\" (
    Echo Using Drive: %MapDrive%:\
 ) ELSE (   
    SET /A TN+=1

If "%LaunchPath:~0,2%" == "\\" (
  echo Network Path: %~dp0
  net use %MapDrive%: %LaunchPath% /persistent:no
  cd /D %MapDrive%:\cmd
  call DoUpdate.cmd %*
  cd /D %SystemDrive%   
  net use %MapDrive%: /delete
) else (
  cd /D %~dp0cmd
  call DoUpdate.cmd %*


Re: Update.cmd code suggestion

Postby Dalai » 12.07.2017, 18:15

Could you please elaborate some more on where the advantages are?

BTW: As I see it you can replace the whole "loop to find the next free drive letter" by a pair of pushd/popd commands; they already find the next free drive letter and use it, even if it's a network drive. So something like
Code: Select all
@echo off
pushd %~dp0
cd cmd
call DoUpdate.cmd %*
should suffice.

Posts: 780
Joined: 12.07.2016, 21:00

Return to Anregungen / Suggestions

Who is online

Users browsing this forum: No registered users and 9 guests