Friday, April 10, 2009

檔名過長怎麼辦

檔名過長怎麼辦

Microsoft微軟技術支援-您無法刪除 NTFS 檔案系統磁碟區上的檔案或資料夾

How to deal with file names that are too long

假設有個檔名叫
thisisafuckinglongfile andyoucantopenit.jpg
其實這不會很長
但打太長會很難閱讀
請發揮想像力
想像這是檔名超過兩百多個字的檔案 XD
太長的檔案會有無法開啟、無法更名的情況發生
解決方法從簡單開始講
全部都是在command line下操作

命令提示字元 開始→執行→cmd
查詢目錄下的檔案:dir/w
切換目錄:cd 目錄位址
回到上一層目錄:cd ..
回到根目錄:cd \
過長或含有空白要在前後加上",例如:
cd "C:\My Documents\My Pictures\"

[Tab]按鍵可以在長檔名間切換,例如有下面兩個資料夾:
thisdictionarywithlongname andveryhardtotype
thisdictionaryisemptybutaverylongdictionaryname
輸入 cd "this[Tab] 會自動變成
cd "thisdictionarywithlongname andveryhardtotype"
再按一次[Tab]會變成
cd "thisdictionaryisemptybutaverylongdictionaryname"

方法1 利用rename變更檔名指令,檔案前後用 " 包起來
格式是 rename 舊檔名 新檔名
所以是:rename "thisisafuckinglongfile andyoucantopenit.jpg" new.jpg

但檔名太長的話
rename 會失敗並傳回 The filename or extension is too long.
試試短檔名法

方法2 先執行 dir/x
會列出像這樣:
thisis~1.jpg thisisafuckinglongfile andyoucantopenit.jpg
前面的thisis~1.jpg就是它的短檔名
由開頭六個字元加上一個 ~ 再加上數字和副檔名
執行 rename thisis~1.jpg new.jpg

若檔名含有空白字元
rename 會失敗並回傳 The system cannot find the path specified.

這很有可能是檔案所在資料夾的名字
加上檔案本身的檔名過長所造成的
例如存在於C:\My Documents\My Pictures\的
thisisafuckinglongfile andyoucantopenit.jpg
可以試著先將資料夾更名
My Documents 改成 D
My Pictures 改成 P
改成 C:\D\P\ 後thisisafuckinglongfile andyoucantopenit.jpg 也許能夠開啟
或直接使用 subst 虛擬磁碟指令:

方法3 首先先挑一個沒在用的磁碟機編號,例如 T
subst T: .
T:
rename "thisisafuckinglongfile andyoucantopenit.jpg" new.jpg
C:
subst T: /d

注意第一行最後一個字元是 .
代表現在的資料夾
這樣一來路徑就縮到最短了
再執行rename
最後一行是關掉虛擬磁碟

若還是不行
就請參考最上面的微軟連結吧
希望對檔名過長有無法開啟困擾的人有幫助!

No comments: