====== 批次將 URL 編碼檔名解碼 ======
像 DokuWiki 預設會將頁面文件檔(.txt)檔名的 UTF-8 字元,用 URL 格式編碼,也就是說非 ASCII 字元都會編為「%30%AB……」這樣的天書。如果在 DokuWiki 的管理介面中想把檔名編碼格式改為 ''utf8'' 還不行,會導致 DokuWiki 抓不到現有的文件檔,會全部亂套。
所以,如果想讓 DokuWiki 改用 UTF-8 檔名的話,還得先把現有文件檔的 URL encoding 全部解碼才行。但哪裡有批次解碼的工具?
* → 找了一下找到[[https://unix.stackexchange.com/questions/159253/decoding-url-encoding-percent-encoding|這裡]]推薦 renameutils。[[http://www.nongnu.org/renameutils/|renameutils home]] 這裡有官方教學。
* 但 renameutils 似乎原本寫給 Linux 作業系統用,那 macOS 上怎辦?
* → 幸好 [[http://macappstore.org/renameutils/|Install renameutils on Mac OSX – Mac App Store]] 這邊有安裝教學。
* → 裝好 renameutils 後,確實可以用 deurlname 這個指令批次解碼。但,它無法處理子目錄裡的檔案啊!!!QQ
* 這邊有一個要 25 歐元的 Windows 小軟體可以處理子目錄下的檔案:[[https://www.3delite.hu/Object%20Pascal%20Developer%20Resources/urldecodefilenames.html|URL Decode Filenames - Convert Filenames - Overview]]
* 或像這篇說的 shell script 來在逐個子資料夾執行指令,有沒有搞頭?[[https://unix.stackexchange.com/questions/171677/cd-into-all-directories-execute-command-on-files-in-that-directory-and-return/171679|shell script - cd into all directories, execute command on files in that directory, and return to previous current directory - Unix & Linux Stack Exchange]]
* ↑/^20190404^/ 好像不完全正確,這邊講的只有進入各個資料夾,但是執行的指令是針對該資料夾本身做一次,而不是對資料夾內每個項目都執行
* /^20190405^/ 目前試:for d in ./* ; do (deurlname $d -v); done
是可以對「單一資料夾」每個項目都做的。接下來我需要的是能自動「進入每個資料夾」的步驟~
* 結果看來好像還是要用 find some/dir -type f -execdir somecommand {} \;
* 但我需要搞懂最後面 ''{}'' 的意思
* [[https://unix.stackexchange.com/questions/195939/what-is-meaning-of-in-finds-exec-command|What is meaning of {} + in find's -exec command? - Unix & Linux Stack Exchange]]
* [[https://unix.stackexchange.com/questions/108216/find-with-execdir|shell - find with -execdir - Unix & Linux Stack ExchangeC]]
* 及 ''\'' 的意思
* 還是搞不太懂,但看來 ''{}'' 和 ''\'' 都省不了 ∴執行了:$ find . -type f -execdir sh -c 'for d in ./*; do (deurlname $d -v); done' {} \;
大致上似乎是可以的(只要解碼後的名稱不要和已有的項目重複即可)
* 最後只要一行find . -d -name "*%*" -exec deurlname {} -v \;
就搞定了!太神奇了!:D 感謝 神
* 不需要套迴圈
* find 的 ''-d'' 是先進下層執行,免得上層解碼後下層失聯