1.

Solve : WIN/BATCH Help with batch program for updating library?

Answer»

Hello

I'm working on program for updating library I made something by others from another forums and got it together but I got problem.

The program should be like this: On desktop will be batch file if I open it, it should detect latest available update based on the name of the folder. The source folder with available updates is in another hard drive (G) There is more versions it LOOKS like this: 

V5_Update_20.22.dir
V5_Update_20.23.dir
V5_Update_20.24.dir
V5_Update_20.25.dir
V5_Update_20.26.dir
V5_Update_20.27.dir

Then It should detect my actual version based on name too, but it is in another hard drive where should be updated the files.

There should be detectable versions like this for program

Catalogumfang_20.22.txt
Catalogumfang_20.23.txt

Based on this it should know which is higher version and it should be copyed like this

content of:
V5_Update_20.24.dir (after DONE go on another version)
V5_Update_20.25.dir (after done go on another version)
V5_Update_20.26.dir (after done go on another version)
V5_Update_20.27.dir (after done go on another version)
-------------------------------------------------------------------------------------
And I'm stuck here: (it only detect version in folder where is batch LOCATED. How can I give it path where is located the source if I put the batch on dekstop)

echo off
setlocal enabledelayedexpansion
set max=0
for %%x in (V5_Update_*) do (
  set "FN=%%~nx"
  set "FN=!FN:V5_Update_=!"
  if !FN! GTR !max! set max=!FN!
)
echo AUDI library latest version: V5_Update_%max%

pause

Thank you guys.The only way I could get a dir list was to change the FOR loop. As I do not have a G: drive I used F: instead. The folders V5_Update_20.22.dir, V5_Update_20.23.dir, etc, are in my folder F:\test. See red bold below. The script works when run from anywhere. The echo commands in the loop are just for testing. You can hard-code the parent folder like below or you can make it a %VAR% or even pass it to the script as a parameter (e.g. %1). Nobody ever ANSWERS my batch solutions, so good luck!

echo off
setlocal enabledelayedexpansion
set max=0
for /f "delims=" %%x in ('dir /ad /b "f:\test\V5_Update_*"') do (
  set "FN=%%~nx"
  echo FN  = !FN!
  set "FN=!FN:V5_Update_=!"
  echo FN  = !FN!
  if !FN! GTR !max! set max=!FN!
  echo max = !max!
)
echo AUDI library latest version: V5_Update_%max%

pause



Discussion

No Comment Found