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-07-15 22:36
中国DOS联盟论坛 » WinPE、PowerShell及其它命令行系统专区 » [Discussion] There are issues with the CMD auto-complete feature for Chinese file and directory names View 5,912 Replies 8
Original Poster Posted 2006-06-08 01:19 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
To All:

Recently, when discussing and improving a batch script for regular backups with Brother namejm, a problem was encountered and I am now bringing it up for everyone's advice.

After enabling the auto-completion feature with cmd /f:on, it was found that if there are directories or files with Chinese names in the test directory, using Ctrl+D or Ctrl+F can normally complete the directory or file name. However, when continuing to use Ctrl+D or Ctrl+F to complete and the next directory or file name is shorter than the completed directory or file name, after displaying the new directory or file name, the old directory and file name does not completely disappear, but leaves a certain trace.

For example, the test folder has only two files named "Long Filename" and "Short Name". Then, after enabling cmd /f:on for auto-completion, pressing Ctrl+F for the first time will display "Long Filename", and pressing Ctrl+F for the second time will display "Short Name Name".

It needs to be noted that the residual trace of the old file will not affect the normal recognition of the new file.

It is analyzed that this should be caused by the auto-completion not correctly handling multi-byte character (including Chinese) file names. In the above test, before the second auto-completion, it only cleared the first three Chinese characters of the previous display, with a width equivalent to 6 English characters. This seems to be because cmd calculates the string length of the previous completed file name according to the Unicode rule as 4, plus the two characters 0d/0a represented by the carriage return, totaling 6. That is to say, cmd rewrites the original file name with 6 English blank characters to clear its display content, but may not have considered that the display width of multi-byte characters is several times that of English characters.

File Backup Tool
http://www.cn-dos.net/forum/viewthread.php?tid=20747&fpage=1
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 2 Posted 2006-06-08 21:50 ·  中国 四川 成都 联通
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Hehe, in the cmd above XP, you don't need /f:on, using Tab / Shift+Tab can also achieve the corresponding function~~ Just like *nux~~

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 3 Posted 2006-06-09 07:54 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
electronixtar is really a thoughtful person, finding such a hidden function, PF.

But using Tab/Shift+Tab also causes the problem of file name residue of Ctrl+F or Ctrl+D. Other problems are not found because I can't think of a way to test them.

Hehe, CMD is getting more and more interesting.
Floor 4 Posted 2006-06-09 16:51 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re electronixtar:

Briefly searched on Google about information regarding autocompletion.

In non-Microsoft website information, it is clearly stated or implied that autocompletion is disabled by default, and needs cmd /f or cmd /f:on to enable.

In Microsoft website published information, most articles reposted the help information of CMD, "File and directory name completion is NOT enabled by default." or "ile and Directory name completion is NOT enabled by default."

Found some useful information in TechNet:

There are two subkeys and four entries related to autocompletion in the registry:

HKLM\Software\Microsoft\Command Processor\CompletionChar
HKLM\Software\Microsoft\Command Processor\PathCompletionChar
HKCU\Software\Microsoft\Command Processor\CompletionChar
HKCU\Software\Microsoft\Command Processor\PathCompletionChar

Under normal conditions, as long as one of these four entries has a value of a control character, autocompletion will be enabled. PathCompletionChar only completes directory names, and CompletionChar completes file names and directory names. When both are set, the settings in HKCU take precedence over HKLM. After using cmd /f, the autocompletion character will be fixed as Ctrl+D/Ctrl+F, regardless of the key values in HKCU/HKLM.

The key is the issue of default values, because if CompletionChar is 0x0, 0xD, or greater than >=0x20, autocompletion will be disabled (actually because it does not meet the activation conditions and cannot be activated). And there is a contradiction in the description of default values in TechNet articles . has a default value of 0x9, which is Tab, has a default value of 0x40, which is disabled.

In addition, the relevant TechNet articles are in the Windows Server 2003 technical library, and are not directional for XP and 2000. In my current XP system, CompletionChar is 0x9, but my system is not an original version, but an optimized version, and I have also modified CompletionChar myself. It is also impossible to rule out whether ServicePack or HotFix has ever modified it.

So, this issue still needs further verification.

CompletionChar Entry
http://technet2.microsoft.com/WindowsServer/en/Library/1ff97534-38d4-4cc1-86f1-c2fc2689367a1033.mspx?mfr=true

Command Processor\CompletionChar
http://technet2.microsoft.com/WindowsServer/en/Library/1ff97534-38d4-4cc1-86f1-c2fc2689367a1033.mspx?mfr=true
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2006-06-11 17:49 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
In the very early days, I found that typing ALT+9 in the command prompt would get a certain file name in the current directory. Later I found out that ALT+9 is TAB. Then I successively found that ESC can cancel the current input, and F1 to F9 have different functions, but most are related to DOSKEY.

Then one day I also discovered the problem described by willsort. At that time, I was at a loss, until one day I found out the function of chr(13) and suddenly understood:

With Wscript.StdOut
.Write "Hello, this is the China DOS Union Script Edition"
Wscript.Sleep 1000
.Write chr(13) & "error"
end With

After saving as 测试.vbs, run cmd and type cscript //b //nologo to see the result.
If you use the writeline method instead of the write method, it will automatically go to the next line and this phenomenon will not occur.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
yayumyself +1 2007-02-28 13:43
Floor 6 Posted 2006-06-11 19:28 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re 3742668:

What you mentioned about chr(13) should be the carriage return character (0x0d). In the DOS semantics, it only carries out a carriage return without a line feed, and the line feed is controlled by the line feed character (0x0a; chr(10)).

The different combinations of carriage return and line feed result in the differences in the plain text formats of the three major systems: MSOS, Unix, and Mac. MSOS uses 0d0a, Unix uses 0a, and Mac uses 0d.

But this is still different from the issue of auto-completion. According to the above view, after "longname", "sname" should be displayed as "sname e" instead of "sname". And if there are both Chinese and English characters in the file name, you can more easily see the problem.

And according to its mode of being able to clear by length rather than by block, the most likely clearing algorithm it uses is to replace all the characters in the original buffer with blank characters, or to re-generate an equal-length string composed of blank characters, and then output it again in the original position (similar to.Write). And because the compilation system uses Unicode encoding, English and Chinese characters with different display widths have the same byte length and character length, so the error can be expected.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
yayumyself +1 2007-02-28 13:45
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 7 Posted 2006-06-15 19:19 ·  中国 江苏 苏州 吴江区 电信
初级用户
Credits 141
Posts 22
Joined 2004-06-07 00:00
22-year member
UID 26188
Gender Male
Status Offline
Floor 8 Posted 2006-10-08 05:57 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

The script of the moderator on the 5th floor is quite interesting, but I still don't understand it. I thought that after displaying "Hello, this is the China DOS Union Script Edition", pressing Enter would change to a new line and then display "error", but the result was not what I imagined. Instead, it was displayed on the same line, and the subsequent "This is the China DOS Union Script Edition" was still retained, which is similar to the incomplete phenomenon of auto-completion. Moderator 3742668, can you explain the role of "chr(13)" in this script?
Floor 9 Posted 2008-01-21 22:18 ·  IANA 局域网IP(Private-Use)
新手上路
Credits 6
Posts 2
Joined 2008-01-21 13:31
18-year member
UID 109157
Gender Male
Status Offline
I think it's adding spaces.
Forum Jump: