嘗試解壓縮子目錄中的檔案時發生錯誤:警告:檔案名稱不匹配

嘗試解壓縮子目錄中的檔案時發生錯誤:警告:檔案名稱不匹配

所以我有一個腳本,它迭代 zip 文件,使用 unzip -l $filename 列出其內容,並查找與模式匹配的內容(.*)report.xml,在本例中產生 test0\report.xml

但是當它嘗試使用解壓縮時unzip -j $filename,我得到caution: filename not matched: test0\report.xml

我停下來手動嘗試一個文件,其中列出了:

7285 2018-05-04 13:34 test0\report.xml

然後做

unzip -j 2747693b-7027-44d3-98f4-a01f1ed139cf.zip test0\report.xml

給我錯誤caution: filename not matched: test0report.xml

我嘗試調用 with\\來逃避它,然後出現同樣的錯誤,但test0\report.xml改為說。

我嘗試了諸如 \、或 / 或 // 之類的所有內容,所以我不認為這是反斜線轉義問題。

請幫忙。

答案1

我已經在我的 Kubuntu 中重現了這個問題。文件名是字面意思test0\report.xml,當我這樣做時

unzip -j foo.zip test0\\report.xml

unzip返回,filename not matched: test0\report.xml儘管我認為它得到的字串應該匹配。

該工具支援一些通配符。我能夠使用以下命令解壓縮該檔案:

unzip -j foo.zip 'test0?report.xml'

一個錯誤?我想您必須在腳本中添加一些邏輯,或者每當這種(希望很少見)情況再次發生時手動解壓縮。或利用 和 支援的這些通配符unzip,而不是(.*)report.xml在腳本中進行匹配,讓我們unzip完成這項工作:

unzip -j foo.zip '*report.xml'

相關內容