复制名称在一定范围内的数字的文件
Copying files with the names having a number within a range
我不熟悉 Powershell(除了它的存在和 运行 一个 powershell 命令的方式)。我有一个文件夹 source。在该文件夹中,我有几个文件:
image_001.jpg
image_002.jpg
...
...
image_250.jpg
...
...
...
image_8000.jpg
其中我想要 select 特定图像,比如来自 image_00001.jpg - image_00250.jpg 并将它们复制到目标文件夹,比如, 目的地
任何人都可以告诉我 powershell 的命令吗?
对于这样的菜鸟问题,我深表歉意。我对 powershell 一无所知,尽管我的直觉告诉我这可能是最容易完成的任务。
注意: 我试图理解关于做类似任务的其他答案,但由于我对 regex 缺乏了解,我是看不懂。
您可以执行以下操作:
cls
$source = "<your source>"
$destination = "<your destination>"
foreach ($i in Get-ChildItem -Path $source -Recurse)
{
if ($i.Name -match "image_(000\d\d|001\d\d|002[0-4]\d|00250)\.jpg")
{
Copy-Item -Path $i.FullName -Destination $i.FullName.Replace($source,$destination).Trim($i.Name)
}
}
正则表达式的解释:
000\d\d|001\d\d|002[0-4]\d|00250
匹配 00000-00250
中的数字
000\d\d
与模式 000(any digit)(any digit)
匹配,即直到 00099
001\d\d
匹配 001(any digit)(any digit)
即来自 00100 to 00199
002[0-4]\d
匹配 002(any digit from 0 to 4)(any digit)
即从 00200 到 00249`
00250
匹配文字 00250
|
或运算符.. 以匹配上述任何指定模式
我不熟悉 Powershell(除了它的存在和 运行 一个 powershell 命令的方式)。我有一个文件夹 source。在该文件夹中,我有几个文件:
image_001.jpg
image_002.jpg
...
...
image_250.jpg
...
...
...
image_8000.jpg
其中我想要 select 特定图像,比如来自 image_00001.jpg - image_00250.jpg 并将它们复制到目标文件夹,比如, 目的地
任何人都可以告诉我 powershell 的命令吗?
对于这样的菜鸟问题,我深表歉意。我对 powershell 一无所知,尽管我的直觉告诉我这可能是最容易完成的任务。
注意: 我试图理解关于做类似任务的其他答案,但由于我对 regex 缺乏了解,我是看不懂。
您可以执行以下操作:
cls
$source = "<your source>"
$destination = "<your destination>"
foreach ($i in Get-ChildItem -Path $source -Recurse)
{
if ($i.Name -match "image_(000\d\d|001\d\d|002[0-4]\d|00250)\.jpg")
{
Copy-Item -Path $i.FullName -Destination $i.FullName.Replace($source,$destination).Trim($i.Name)
}
}
正则表达式的解释:
000\d\d|001\d\d|002[0-4]\d|00250
匹配 00000-00250
000\d\d
与模式000(any digit)(any digit)
匹配,即直到00099
001\d\d
匹配001(any digit)(any digit)
即来自00100 to 00199
002[0-4]\d
匹配002(any digit from 0 to 4)(any digit)
即从 00200 到 00249`00250
匹配文字00250
|
或运算符.. 以匹配上述任何指定模式