1.

Solve : Syntax problem with the FOR command?

Answer» <html><body><a href="https://interviewquestions.tuteehub.com/tag/hi-479908" style="font-weight:bold;" target="_blank" title="Click to know more about HI">HI</a>,<br/><br/>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:<br/><br/>    DIR "C:\test\datafile.*" /b &gt; C:\data.lst"<br/>   <br/>    FOR /F "eol= " %%i IN (C:\data.lst) DO (<br/>       SET FileExt=%%i:~<a href="https://interviewquestions.tuteehub.com/tag/9-miliyn-237742" style="font-weight:bold;" target="_blank" title="Click to know more about 9">9</a>%<br/>       ECHO %FileExt%<br/>    )<br/><br/><br/>The contents of "C:\data.lst" looks like:<br/><br/>    datafile.1<br/>    datafile.7<br/>    datafile.25<br/>    datafile.98<br/>    datafile.167<br/>    datafile.817<br/><br/><br/>ThanksI figured it out, I <a href="https://interviewquestions.tuteehub.com/tag/needed-1112853" style="font-weight:bold;" target="_blank" title="Click to know more about NEEDED">NEEDED</a> to use the <a href="https://interviewquestions.tuteehub.com/tag/setlocal" style="font-weight:bold;" target="_blank" title="Click to know more about SETLOCAL">SETLOCAL</a> command and instead of using % I needed to use !.  This is the syntax I'm using:<br/><br/>    DIR "C:\test\datafile.*" /b &gt; "C:\data.lst"<br/>   <br/>    SetLocal EnableDelayedExpansion<br/>    FOR /F "eol= " %%i IN (C:\data.lst) DO (<br/>       SET DataFile=%%i<br/>       SET FileExt=!DataFile:~9!<br/>       ECHO !FileExt!<br/>    )<br/>    EndLocal<br/><br/>If anyone has any better ideas to do this, I'm all ears!!set fileExt=%%~xi<br/><br/>type FOR /? at the prompt for full help<br/></body></html>


Discussion

No Comment Found