【发布时间】:2022-01-15 22:13:05
【问题描述】:
我的 Google 云端硬盘因未知原因创建了某些文件的多个副本,格式如下:文件名 (2021_02_08 11_22_39 UTC).ext
我想将这些文件移到另一个文件夹中,以防万一。 我发现这个线程here 看起来很相似。 我不是正则表达式的专家。你能帮我解决这个问题吗?
正则表达式:[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
}
【问题讨论】:
-
您还可以将
-Filter '????_??_?? ??_??_?? UTC.ext'添加到您的搜索中以使其更快。 -
这个八 (8) 年前的答案看起来很熟悉。 stackoverflow.com/a/18165832/447901
标签: regex powershell