May 23, 2021 DOS Command learning manual
1, about the colon: when a line of content to : head, with for /f "tokens" 1 x delims: "%%in ('findstr /n .test.txt') do echo%%j will filter out: ;
2, about the sign: findstr .?test.txt can be used in the for statement can not be found in full, must be added parameters / n can, it seems that the for statement will start with the line as a comment content ignored, as if it is not findstr's fault;
Solutions to problem 1 and 2 are:
Slightly more complex:
@echo off
:: Empty lines are not ignored
for /f "delims=" %%i in ('findstr /n .* test.txt') do (
set "str=%%i"
call set "str=%%str:*:=%%"
call echo "%%str%%"
)
pause
The simplest:
@echo off
:: This code ignores empty lines
for /f "delims= eol=" %%i in (test.txt) do echo %%i
pause
3, in the for extension, %%-si indicates that the path to the extension contains only short file names, but in the following testing process, it is found that this is not the case:
Test environment:
--------------------------------------------------------------------------------
D:\abcdefg hijk\abcd efgh.txt
D:\abcdefg hijk\te st.txt
Test code:
--------------------------------------------------------------------------------
@echo off
for /f "delims=" %%i in ('dir /a /b *.txt') do echo %%~si
pause
Test results:
--------------------------------------------------------------------------------
D:\ABCDEF~1\ABCDEF~1.TXT
D:\ABCDEF~1\TEST~1.TXTtxt
See the last record of the test results? actually extended to TEST-1.TXTtxt!
To sum up the error, it seems that when more than one place in the path is expanded to a short file name because the directory name exceeds 11 characters, an extension error occurs for a file with a file name with a suffix name of less than 11 characters and a space.
—— namejm