由于未知原因,我的 Google 云端硬碟以以下格式創建了某些檔案的多個副本:檔案名 (2021_02_08 11_22_39 UTC).ext
我想將這些檔案移動到另一個檔案夾中,以防萬一。我在這里找到了這個看起來很相似的執行緒。我不是正則運算式的專家。你能幫我解決這個問題嗎?
正則運算式:[a-zA-Z] )。用于搜索:UTC)。
我想它應該是這樣的:
$source = "C:\Dropbox"
$destination = "C:\DropboxDupes"
gci .\Dropbox -Recurse -File | ?{ $_.basename -match "[a-zA-Z] \)\."} | % {
$destination_filename = $_.fullname.Replace($source, $destination)
$destination_dir = split-path $destination_filename -Parent
if(-not (Test-Path $destination_dir -PathType Container)) {
mkdir $destination_dir | out-null
}
move-item $_.fullname $destination_filename
}
uj5u.com熱心網友回復:
嘗試'\([\d_\s] UTC\)'匹配數字、下劃線和空格后跟“UTC”以及所有括在括號中的內容。
腳本撰寫的最佳實踐是不要使用別名、使用引數名稱并堅持大小寫。
$source = "C:\Dropbox"
$destination = "C:\DropboxDupes"
Get-ChildItem -Path $source -Recurse -File |
Where-Object { $_.BaseName -match '\([\d_\s] UTC\)'} |
ForEach-Object {
$destination_filename = $_.FullName.Replace($source, $destination)
$destination_dir = Split-Path -Path $destination_filename -Parent
if (-not (Test-Path -Path $destination_dir -PathType Container)) {
New-Item -Type Directory -Path $destination_dir | Out-Null
}
Move-Item -Path $_.FullName -Destination $destination_filename
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/379958.html
上一篇:命令控制臺輸出-到檔案。獲取{WindowsFilteringPlatform/WindowsFirewall}規則
