Renaming files by reformatting existing filenames - placeholders in replacement strings used with the -replace operator

后端 未结 4 1119
醉话见心
醉话见心 2020-11-21 22:23

I have a few video file like this: VideoName_s01e01.mp4 where the season and episodes are variables. I want to add an underscore (\"_\") between the s??

4条回答
  •  广开言路
    2020-11-21 23:04

    regex is the better solution, i propose other with formating number and use Template

    $exampleoffile = @"
    namev1_s01e01.mp4
    namvev2_s03e02.mp4
    VideoName_s20e15.mp4
    VideoName_s15e1.mp4
    VideoName_s1e16.avi
    VideoName_s1e23.mv
    "@
    
    $template=@"
    {file*:{prefix:Test1}_s{season:01}e{episode:01}{extension:.mp4}}
    {file*:{prefix:1xxx}_s{season:100}e{episode:5}{extension:.mp4}}
    {file*:{prefix:yyy3}_s{season:10}e{episode:02}{extension:.havi}}
    "@
    
    
    
    $exampleoffile | ConvertFrom-String -TemplateContent $template | 
    % { "{0}_{1:D2}_e{2:D2}{3}" -f $_.file.prefix, [int]$_.file.season, [int]$_.file.episode, $_.file.extension }
    

提交回复
热议问题