简体   繁体   English

根据名称移动文件(额外复杂)

[英]Move files based on name (with an extra complication)

I´ve seen a couple of topics showing how to move files based on their names. 我看过几个主题,展示了如何根据文件名移动文件。 I have an extra issue with this matter. 我对此事还有其他问题。 I have a bunch of video files, based on tv series with the 我有一堆基于电视连续剧的视频文件
name of the series + season + episode number
For example: Breaking.Bad.s01e03 例如: Breaking.Bad.s01e03
And my files are organized like: 我的文件组织如下:

d:\series\breaking bad\season01
d:\series\breaking bad\season02
d:\series\breaking bad\season03
...
etc

What i need is a script that checks for series name+season and moves them to it's corresponding folder. 我需要的是一个脚本,用于检查系列名称和季节,并将它们移到相应的文件夹中。 Is it possible? 可能吗?

thanks in advance 提前致谢

i got bored and decided to answer your question even tho you have ignored the "how to ask a good question" info ... [ frown ] 我很无聊,并决定回答您的问题,即使您忽略了“如何提出一个好问题”信息... [ 皱眉 ]

the OP needs this to be case-insensitive - and the .Replace() method is not. OP需要不区分大小写-而.Replace()方法不是。 changed to use the -replace operator instead. 改为使用-replace运算符。

$FileName = 'Breaking.Bad.S01e03'

$Series = $FileName.Substring(0, $FileName.LastIndexOf('.')).Replace('.', '_')
# disabled the initial version since the OP now needs case-insensitive replacement
#$Season = $FileName.Split('.')[2].Split('e')[0].Replace('s', 'Season')
$Season = $FileName.Split('.')[2].Split('e')[0] -replace 's', 'Season'

$Series
$Season

output ... 输出...

Breaking_Bad
Season01

i will leave to you the process of building a path from the above AND how to move files. 我将为您提供从上述内容构建路径以及如何移动文件的过程。 [ grin ] here's a pair of hints ... [ 咧嘴 ]这是一条提示...

Get-Help Join-Path
Get-Help Move-Item

the OP has changed the entire format of the files, so this is a version that works with that format. OP更改了文件的整个格式,因此这是可使用该格式的版本。 no other formats were given, so no other formats were coded for. 没有给出其他格式,因此没有编码其他格式。

if there are other formats needed, and the OP is unable to code for them, please ask a new question. 如果需要其他格式,并且OP无法为其编码,请提出一个新问题。

# fake reading in filenames
#    in real life, use Get-ChildItem
$FileList = @(
    [System.IO.FileInfo]'Breaking.Bad.S01E01.DVDRip.XviD-ORPHEUS.avi'
    [System.IO.FileInfo]'Breaking.Bad.s02E01.DVDRip.XviD-ORPHEUS.avi'
    [System.IO.FileInfo]'Breaking.Bad.S03e01.DVDRip.XviD-ORPHEUS.avi'
    [System.IO.FileInfo]'Breaking.Bad.s04e01.DVDRip.XviD-ORPHEUS.avi'
    )

foreach ($FL_Item in $FileList)
    {
    $SeriesName = ($FL_Item.BaseName -split '\.s\d')[0].Replace('.', '_')
    $SE_Info = $FL_Item.BaseName.Split('.')[-3] -split 'e'

    $Season = $SE_Info[0] -replace 's', 'Season'
    $Episode = 'Episode{0}' -f $SE_Info[1]

    $SeriesName
    $Season
    $Episode
    ''
    }

output ... 输出...

Breaking_Bad
Season01
Episode01

Breaking_Bad
Season02
Episode01

Breaking_Bad
Season03
Episode01

Breaking_Bad
Season04
Episode01

again, i will refer you to Join-Path , New-Item, and Move-Item for creating the destination paths and moving the files. 再次,我将引导您参考Join-Path ,New-Item和Move-Item来创建目标路径和移动文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM