依據MSDN文件,檔名或目錄名稱不應以句點"."或空白結尾:

Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, ".temp".

只是,其中也提到這個限制是來自Windows Shell層,部分檔案系統可以接受,於是,我們可能會看到如下情況。在InvFileName目錄下有一個機車檔案"TrailingPeriod.”、兩個機車目錄"TrailingSpace "跟"DirTrailingPeriod.",DIR可以看到,卻無法檢視目錄或檔案內容,不能更名也沒辦法刪除,不管用命令列指令或是開檔案總管都束手無策,讓人充滿無力感!

D:\InvFileName>dir
 Volume in drive D has no label.
 Volume Serial Number is 0F24-3000

 Directory of D:\InvFileName

2012/12/14  下午 08:26    <DIR>          .
2012/12/14  下午 08:26    <DIR>          ..
2012/12/14  下午 08:27                 7 TrailingPeriod.
2012/12/14  下午 08:29    <DIR>          TrailingSpace
2012/12/14  下午 08:30    <DIR>          DirTrailingPeriod.
               1 File(s)              7 bytes
               4 Dir(s)   3,907,305,472 bytes free

D:\InvFileName>type TrailingPeriod.
The system cannot find the file specified.

D:\InvFileName>dir "TrailingSpace "
 Volume in drive D has no label.
 Volume Serial Number is 0F24-3000

 Directory of D:\InvFileName

File Not Found

D:\InvFileName>dir DirTrailingPeriod.
 Volume in drive D has no label.
 Volume Serial Number is 0F24-3000

 Directory of D:\InvFileName

File Not Found

爬文許久,好不容易摸索出正確關鍵字"Trailing Period",才露出曙光...

微軟有篇KB 您無法刪除 NTFS 檔案系統磁碟區上的檔案或資料夾 提到了"\\? \x:\folder_name\invalid_filename”URI表示法,經測試果然可以克服問題,但卻發現,這招對句點結尾的目錄似乎無效(如下方黃字區所示),最後繞了個彎,使用"8.3短名稱"密技,推測出"DirTrailingPeriod."的8.3短名為"DirTra~1",總算成功存取目錄。

D:\InvFileName>type "\\?\d:\InvFileName\TrailingPeriod."
Cool!!!
D:\InvFileName>dir "\\?\d:\InvFileName\TrailingSpace " /w
 Volume in drive \\?\d: has no label.
 Volume Serial Number is 0F24-3000

 Directory of \\?\d:\InvFileName\TrailingSpace

[.]  [..]
               0 File(s)              0 bytes
               2 Dir(s)   3,907,309,568 bytes free

D:\InvFileName>dir "\\?\d:\InvFileName\DirTrailingPeriod." /w
 Volume in drive \\?\d: has no label.
 Volume Serial Number is 0F24-3000

 Directory of \\?\d:\InvFileName\DirTrailingPeriod

File Not Found

D:\InvFileName>dir "\\?\d:\InvFileName\DirTra~1" /w
 Volume in drive \\?\d: has no label.
 Volume Serial Number is 0F24-3000

 Directory of \\?\d:\InvFileName\DirTra~1

[.]  [..]
               0 File(s)              0 bytes
               2 Dir(s)   3,907,309,568 bytes free

Comments

# by mj

dir /x 短名稱立即現型,不需推敲

# by alexyeh09@gmail.com

受用

# by Jeffrey

to mj, dir /x這招好用(抄筆記...),感謝分享

Post a comment