Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: WIN/BATCH Help with batch program for updating library  (Read 4202 times)

0 Members and 1 Guest are viewing this topic.

CrudeBrent

    Topic Starter


    Newbie

    • Experience: Familiar
    • OS: Windows 10
    WIN/BATCH Help with batch program for updating library
    « on: October 04, 2019, 06:28:57 AM »
    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.

    Salmon Trout

    • Guest
    Re: WIN/BATCH Help with batch program for updating library
    « Reply #1 on: October 04, 2019, 12:11:52 PM »
    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