Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

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

Jan
755
16
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 ...
 
Last edited:
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?
 
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]
 
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.
 
FOR seems so old-fashioned. Try DO.

Code:
do i in /p DIR C_VOL-b*.spf /B /Ord (@SET OldestFileInDirCVolSPF=%i)
 
FOR seems so old-fashioned. Try DO.

Code:
do i in /p DIR C_VOL-b*.spf /B /Ord (@SET OldestFileInDirCVolSPF=%i)
Works! Thank you very much both!

Should I make a bug report about broken FOR or could it be "by design" in new version?
 
Rex will probably read this thread. I doubt it's by design. TCC tries to maintain compatibility with CMD.
 
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 ...
By the way: that was complete nonsense from me! Of course I must test the file date!
 
Back
Top
[FOX] Ultimate Translator
Translate