我正在尋找一系列遵循非常嚴格的檔案名格式的檔案,但基于檔案名中的字串位于不同編號的子檔案夾中。
檔案名始終為“LAX_CA_Baseball_<8 位數字>.pdf
檔案總是 4 個檔案夾深,前兩個檔案夾總是 \\fileserver\sports\pdf
最后 4 位數字始終代表底部的兩個子檔案夾,例如 LAX_CA_Baseball_12345678.pdf 將位于“\\fileserver\sports\pdf\56\78”
總共有幾千萬個檔案,所以僅僅從\\fileserver\sports\pdf中搜索檔案名會花費很長時間
我可以在powershell中寫一些東西來決議檔案名的最后4位數字,將其轉換為底部的子檔案夾,然后獲取檔案并將其復制到一個新檔案夾中嗎?
uj5u.com熱心網友回復:
假設您已經在某處獲得了檔案名,您可以提取數字并使用正則運算式構造路徑:
$f = "LAX_CA_Baseball_12345678.pdf"
if ($f -match ".*_\d{4,4}(\d\d)(\d\d)\.pdf") {
$sourcePath = "\\server\sports\pdf\$($matches[1])\$($matches[2])\$f"
$destinationPath = "some other folder path"
Copy-Item $sourcePath $destinationPath
} else {
Write-Error "Can't determine folder from filename $f"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/410067.html
標籤:
