1.

Solve : Syntax problem with the FOR command?

Answer» HI,

I'm trying to extract File extensions (8.3) from a text file but I can't get it to work, any ideas?  Here is the code i'm trying to use:

    DIR "C:\test\datafile.*" /b > C:\data.lst"
   
    FOR /F "eol= " %%i IN (C:\data.lst) DO (
       SET FileExt=%%i:~9%
       ECHO %FileExt%
    )


The contents of "C:\data.lst" looks like:

    datafile.1
    datafile.7
    datafile.25
    datafile.98
    datafile.167
    datafile.817


ThanksI figured it out, I NEEDED to use the SETLOCAL command and instead of using % I needed to use !.  This is the syntax I'm using:

    DIR "C:\test\datafile.*" /b > "C:\data.lst"
   
    SetLocal EnableDelayedExpansion
    FOR /F "eol= " %%i IN (C:\data.lst) DO (
       SET DataFile=%%i
       SET FileExt=!DataFile:~9!
       ECHO !FileExt!
    )
    EndLocal

If anyone has any better ideas to do this, I'm all ears!!set fileExt=%%~xi

type FOR /? at the prompt for full help


Discussion

No Comment Found