In the for expansion, %%~si means the expanded path contains only the short file name. But in the following test process, it was found that the actual situation is not the case:
Test environment:
Test code:
Test result:
Did you see the last record of the test result? It actually expanded to TEST~1.TXTtxt!
Summarizing the error situation, it seems that when there are more than one places in the path where the directory name is expanded to a short file name because it exceeds 11 characters, a file with a file name + suffix name less than 11 characters and with spaces will have an expansion error. I wonder if someone can make a deep analysis.
[ Last edited by namejm on 2007-1-24 at 02:22 PM ]
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 result:
D:\ABCDEF~1\ABCDEF~1.TXT
D:\ABCDEF~1\TEST~1.TXTtxt
Did you see the last record of the test result? It actually expanded to TEST~1.TXTtxt!
Summarizing the error situation, it seems that when there are more than one places in the path where the directory name is expanded to a short file name because it exceeds 11 characters, a file with a file name + suffix name less than 11 characters and with spaces will have an expansion error. I wonder if someone can make a deep analysis.
[ Last edited by namejm on 2007-1-24 at 02:22 PM ]
Recent Ratings for This Post
( 1 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| redtek | +10 | 2007-01-30 22:07 |
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
考虑问题复杂化,解决问题简洁化。

