1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? Problem with FOR/DO(?) since v18.00.19 ...

Discussion in 'Support' started by Alpengreis, Jun 24, 2015.

  1. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    In a directory, I have different files such as ...

    C_VOL-b516.spf
    C_VOL-b515.spf
    C_VOL-b514.spf
    C_VOL-b513.spf

    To find out which is the file with the lowest number (is the oldest file), I used till now the following command sequence (within this directory):

    FOR /F %%i IN ('DIR C_VOL-b*.spf /B /Ord') DO @SET OldestFileInDirCVolSPF=%%i

    and then the variable %OldestFileInDirCVolSPF% ...

    this is no more possible - the variable is empty now.

    What is here the problem?

    Thank you very much for help in advance!

    Kind regards
    Alpengreis

    EDIT ...
    PS: I can not test for the oldest file date (the date is not ALWAYS relevant, I can only test for the numbers within filename - the lowest number is always the oldest for my purpose ...
     
    #1 Alpengreis, Jun 24, 2015
    Last edited: Jun 24, 2015
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    If you type the DIR command by itself, do you get any results?
    If you replace the DO @SET with DO echo @SET what are your results?
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    The DO command works correctly. But FOR is broken in build 19.
    Code:
    do i in /p DIR C_VOL-b*.spf /B /Ord (set OldestFileInDirCVolSPF=%i)
    
    Another option uses @execstr
    Code:
    set OldestFileInDirCVolSPF=%@execstr[dir C_VOL-b*.spf /b /od]
    
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,935
    Likes Received:
    30
    There is a difference but I can't say when it started. Here's v17.
    Code:
    g:\tc17> for /f %%i in ('echo foo') do echo %i
    foo
    V18 produces nothing.
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,935
    Likes Received:
    30
    FOR seems so old-fashioned. Try DO.

    Code:
    do i in /p DIR C_VOL-b*.spf /B /Ord (@SET OldestFileInDirCVolSPF=%i)
     
  6. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    Works! Thank you very much both!

    Should I make a bug report about broken FOR or could it be "by design" in new version?
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,935
    Likes Received:
    30
    Rex will probably read this thread. I doubt it's by design. TCC tries to maintain compatibility with CMD.
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
  9. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    By the way: that was complete nonsense from me! Of course I must test the file date!
     

Share This Page