China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 05:42
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A bug in the short filename extension of the for expansion View 2,758 Replies 9
Original Poster Posted 2007-01-24 23:24 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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:

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
RaterScoreTime
redtek +10 2007-01-30 22:07
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 2 Posted 2007-01-25 00:07 ·  中国 广东 深圳 福田区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
I have experienced this bug before
第一高手 第二高手

Floor 3 Posted 2007-01-25 00:47 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  Hehe, it turns out it's like this.
Floor 4 Posted 2007-01-30 16:12 ·  中国 广东 广州 黄埔区 电信
初级用户
Credits 20
Posts 9
Joined 2007-01-24 16:40
19-year member
UID 77557
Gender Male
Status Offline
Floor 5 Posted 2007-01-30 21:16 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Haven't encountered it yet, just in time to learn. ^_^
Floor 6 Posted 2007-02-08 22:40 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
Got it, learned something
Floor 7 Posted 2007-03-08 16:16 ·  中国 四川 成都 电信
中级用户
★★
Credits 297
Posts 135
Joined 2006-10-21 12:00
19-year member
UID 67627
Gender Male
Status Offline
It's not like you said, because spaces are not allowed in the short names of files/folders that contain spaces. This is not a bug of for.
Floor 8 Posted 2007-05-01 01:34 ·  中国 广东 茂名 电信
新手上路
Credits 12
Posts 6
Joined 2007-04-21 13:21
19-year member
UID 85989
Gender Male
Status Offline
Dizzy
Completely don't understand
It seems that I will have to spend 18 hours a day on the forum in the future
Floor 9 Posted 2007-05-01 03:44 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
In the command specification of 8.3, spaces are not allowed, so when extending the long name to the short name, the spaces are automatically indented
Floor 10 Posted 2007-05-02 15:36 ·  中国 云南 昆明 电信
初级用户
Credits 57
Posts 29
Joined 2006-12-27 09:36
19-year member
UID 74694
Gender Male
Status Offline
It seems I can only educate myself more. Sigh! There are really so many experts and masters here.
Forum Jump: