【冷知識】處理句點或空白結尾的檔案及目錄

依據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
歡迎推文分享:
Published 14 December 2012 09:14 PM 由 Jeffrey
Filed under:



意見

# mj said on 17 December, 2012 06:22 AM

dir /x

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

# alexyeh09@gmail.com said on 18 December, 2012 01:59 AM

受用

# Jeffrey said on 18 December, 2012 07:11 PM

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

你的看法呢?

(必要的) 
(必要的) 
(選擇性的)
(必要的) 
(提醒: 因快取機制,您的留言幾分鐘後才會顯示在網站,請耐心稍候)

5 + 3 =

搜尋

Go

<December 2012>
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345
 
RSS
【工商服務】
OrcsWeb: Windows Server Hosting
twMVC
最新回應

Tags 分類檢視
關於作者

一個醉心技術又酷愛分享的Coding魔人,十年的IT職場生涯,寫過系統、管過專案, 也帶過團隊,最後還是無怨無悔地選擇了技術鑽研這條路,近年來則以做一個"有為的中年人"自許。

文章典藏
其他功能

這個部落格


Syndication