所以我遇到这样的情况...
我的文件夹中有很多文件,如下所示
Iron.Man.2008.1440p.UHD.US.BluRay.x265.HDR.DD5.1-Pahe.in
Iron Man 2008.720p.BrRip.x264.YIFY
Iron.Man.2008.US.RERiP.720p.UHD.BluRay.x264-Pahe.in
Iron.Man.2008.Open.Matte.720p.WEB-HD.x264-Pahe.in
Iron.Man.2008.US.RERiP.1080p.UHD.BluRay.x264.DD5.1-Pahe.in
The.Incredible.Hulk.2008.REMASTERED.1080p.BluRay.x264.DD5.1-Pahe.in
The.Incredible.Hulk.2008.REMASTERED.720p.BluRay.x264-Pahe.in
The.Avengers.2012.2160p.10bit.HDR.BluRay.8CH.x265.HEVC-PSA
The.Avengers.2012.1080p.10bit.BrRip.6CH.x265.HEVC-PSA
The.Avengers.2012.720p.10bit.BrRip.6CH.x265.HEVC-PSA
所以我有多个相同的电影 - 但编码器不同且质量不同。
我想要实现的目标是将所有这些不同的编码移动到一个通用文件夹,其中原始电影名称为标题
例如
Iron.Man.2008
Iron.Man.2008.1440p.UHD.US.BluRay.x265.HDR.DD5.1-Pahe.in
Iron Man 2008.720p.BrRip.x264.YIFY
Iron.Man.2008.US.RERiP.720p.UHD.BluRay.x264-Pahe.in
Iron.Man.2008.Open.Matte.720p.WEB-HD.x264-Pahe.in
Iron.Man.2008.US.RERiP.1080p.UHD.BluRay.x264.DD5.1-Pahe.in
The.Incredible.Hulk.2008
The.Incredible.Hulk.2008.REMASTERED.1080p.BluRay.x264.DD5.1-Pahe.in
The.Incredible.Hulk.2008.REMASTERED.720p.BluRay.x264-Pahe.in
The.Avengers.2012
The.Avengers.2012.2160p.10bit.HDR.BluRay.8CH.x265.HEVC-PSA
The.Avengers.2012.1080p.10bit.BrRip.6CH.x265.HEVC-PSA
The.Avengers.2012.720p.10bit.BrRip.6CH.x265.HEVC-PSA
我曾尝试将其作为bat文件运行..它创建了文件夹,但它根据原始文件名移动文件..每个编码都被移动到它们自己的特定文件夹中
@echo off
for %%a in (*.*) do (
md "%%~na" 2>nul
move "%%a" "%%~na"
)
pause
我愿意接受 Windows 或 Linux 中的任何解决方案
谢谢
既然你也标记了这个PowerShell
,这是一个解决方案:
$sourceFolder = 'D:\Test' # where the files are now
$destination = 'D:\Movies' # where the subfolders storing the files should be created
$regex = '^(\D+[.\s]\d{4})\..*' # see explanation below
(Get-ChildItem -Path 'D:\Test' -File | Where-Object { $_.BaseName -match $regex }) |
ForEach-Object {
$subFolder = ([regex]$regex).Match($_.BaseName).Groups[1].Value -replace '\s', '.'
$targetDir = Join-Path -Path $destination -ChildPath $subFolder
# create the subfolder if it does not yet exist
if (!(Test-Path -Path $targetDir -PathType Container)) {
$null = New-Item -Path $targetDir -ItemType Directory
}
$_ | Copy-Item -Destination $targetDir
}
正则表达式详细信息:
^ # Assert position at the beginning of a line (at beginning of the string or after a line break character)
( # Match the regular expression below and capture its match into backreference number 1
\D # Match a single character that is not a digit 0..9
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
[.\s] # Match a single character present in the list below
# The character “.”
# A whitespace character (spaces, tabs, line breaks, etc.)
\d # Match a single digit 0..9
{4} # Exactly 4 times
)
\. # Match the character “.” literally
. # Match any single character that is not a line break character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)