Windows system uses powershell to batch modify file names

Use powershell to batch modify file names

Write and run .ps1 file

Create a new text document and enter the following content:

#批量修改文件名
# 设置文件夹路径
$folderPath = "D:\111\111_2"

# 获取文件夹中所有文件
$files = Get-ChildItem -Path $folderPath

# 循环遍历每个文件
foreach ($file in $files) {

    # 删除文件名中间的"rwqe"字符
    $newFileName = $file.Name -replace "rwqe", ""

    # 构建新的文件路径
    $newFilePath = Join-Path -Path $folderPath -ChildPath $newFileName

    # 重命名文件
    Rename-Item -Path $file.FullName -NewName $newFilePath
}
# 完成后输出消息
Write-Host "All work completed"

The path is modified according to the situation. The code is saved as a file with the suffix ".ps1", such as "111.ps1".

Open powershell , enter ".\111.ps1" in the path of "111.ps1", and execute the file.

Report an error

Powershell runs instructions. For common errors and their handling, please refer to:

Common errors and solutions for powershell running instructions in Windows systems_weixin_56337147's blog-CSDN blog

How to use powershell in windows10         

1. Open PowerShell :

Press  Win + X the key combination and select Windows PowerShell or Windows PowerShell (Admin) from the pop-up menu.

Type "PowerShell" in the search bar on the taskbar, and then click "Windows PowerShell" or "Windows PowerShell (Admin)" in the search results.

2.Jump path

cd D:/folder_name

3. Execute ps1 file 

.\111.ps1

Summarize 

Write and run .ps1 files to modify file names in batches.

 

Guess you like

Origin blog.csdn.net/weixin_56337147/article/details/133638123