You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell按模式重命名文件:在SxxExx前添加空格

Solution for Renaming Video Files with Space Before Season/Episode Tag

Absolutely, we can adjust your PowerShell script to insert that space before the SxxExx pattern. Here's how to modify it to get your desired filename format:

cd 'C:\Users\ME\Desktop\HERE'
Get-ChildItem -Recurse | Where-Object { -Not $_.PsIsContainer -AND $_.Name -match '\.' } | ForEach-Object {
    # Remove all dots from the base name
    $cleanBase = $_.BaseName.Replace(".", "")
    # Insert space before the SxxExx pattern
    $formattedBase = $cleanBase -replace '(S\d+E\d+)', ' $1'
    # Combine with original extension
    $newName = $formattedBase + $_.Extension
    # Rename the file
    Rename-Item -Path $_.FullName -NewName $newName -PassThru
}

Key Changes Explained:

  • Fixed the File Filter: Your original where clause used -match "." which matches any filename (since . is a regex wildcard for any character). I changed it to -match '\.' to only target files with actual dots in their name.
  • Regex for Space Insertion: The -replace '(S\d+E\d+)', ' $1' part looks for the pattern S followed by one or more digits, then E followed by one or more digits. It replaces that match with a space plus the original pattern, inserting the space exactly where you need it.

Optional Adjustments:

  • Case Insensitivity: If your files might have lowercase s/e (like s01e01), add the case-insensitive flag to the regex:
    $formattedBase = $cleanBase -replace '(?i)(s\d+e\d+)', ' $1'
    
  • Precise Matching: To avoid adding a space if S comes right after a digit (e.g., FileName2S01E01), use a positive lookbehind to ensure S is preceded by a non-digit character:
    $formattedBase = $cleanBase -replace '(?<=[^\d])(S\d+E\d+)', ' $1'
    

Testing this with your example files will turn:

  • File.Name.S01.E01.Mp4 → FileName S01E01.Mp4
  • File.Name.S11.E01.Mp4 → FileName S11E01.Mp4
  • File.Name.S21.E01.Mp4 → FileName S21E01.Mp4

内容的提问来源于stack exchange,提问作者Defca Trick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:03:11