我想將一些帶有長文件名的文件複製到舊的Windows XP 32位FAT32系統上,並且出現文件名太長的錯誤。我如何遞歸搜索文件名大於或等於255個字符的目錄,並將它們截斷爲適合FAT32文件系統?截斷超過255個字符的文件名
1
A
回答
2
我敢肯定find
可以做到全工作,我不能完全得到最後一步,所以採用了一些bash
foo:
#/bin/bash
find . -maxdepth 1 -type f -regextype posix-extended -regex ".{255,}" |
while read filename
do
mv -n "$filename" "${filename:0:50}"
done
使用find
讓所有與文件名大於或等於255個字符的文件:
find . -maxdepth 1 -type f -regextype posix-extended -regex ".{255,}"
截斷這些文件名到50個字符,-n
不覆蓋現有文件。
mv -n "$filename" "${filename:0:50}"
注:這可以與-exec
選項的人?
0
在這裏你去:
find /path/to/base/dir -type f | \
while read filename
do
file="${filename%%.*}"
ext="${filename##*.}"
if [[ "${#file}" -gt 251 ]]; then
truncated=$(expr $file 1 251)
mv "${filename}" "${truncated}"."${ext}"
fi
done
我卻不知道如何可以做到這一點,但一些簡單的修改到first Google result to "unix truncate file name"足以產生上述溶液。試一試第一;)
0
你可以在一個終端與perl
做到這一點:
cd /d \path\to\dir
find . -type f |
perl -F'[/\\]' -lane '
$f = $F[-1];
($ext) = $f =~ /(\.[^.]+)$/;
delete $F[-1];
$path = join "/", @F;
if (length($f) > 255) {
$c++;
rename "$path/$f", "$path/truncated_$c$ext"
}
'
重命名的文件將看起來像:
truncated_1.ext
truncated_2.ext
(...)
相關問題
- 1. 在255個字符處截斷所有文件名的命令
- 2. 數據截斷爲255個字符
- 3. 移動超過255個字符的windows文件夾路徑
- 4. 從文件名中截斷字符串
- 5. 截斷SqlBulkCopy的文本字符255使用SqlBulkCopy的
- 6. 在255個字符處截斷訪問報告字段
- 7. 的Python:ZIP解壓有超過255個字符的字符串
- 8. Excel.Range.Find使用長度超過255個字符的字符串
- 9. 當使用FreeTDS查詢MS SqlServer時,Python截斷255個字符
- 10. 訪問和VBA讀取每行超過255個字符的文本文件
- 11. 如何打印超過255個字符的數組? (VBA字)
- 12. 填寫超過255個字符的單詞表單字段
- 13. delphi'string'文字怎麼能超過255?
- 14. 如何緩存超過255個字符的路徑並讀取文件屬性?
- 15. DBF文件名截斷
- 16. 打到寬字符後截斷文件
- 17. 如何檢索長度超過255個字符的range.address?
- 18. 截斷一個文件名 - 擴展
- 19. x個字符後截斷字符串
- 20. 如何限制訪問字符數超過255個
- 21. 實體@Column長度超過255個字符
- 22. PHP到Excel,不允許超過255個字符?
- 23. 訪問令牌是否可以超過255個字符?
- 24. Excel無法插入超過255個字符?
- 25. 如何在MySQL數據庫中存儲超過255個字符?
- 26. RWDBReader無法讀取超過255個字符
- 27. Word宏無法保存文件名> 255個字符
- 28. Usigned char超過255
- 29. 如何創建名稱超過260個字符的文件夾
- 30. php chr()的數字超過255