简体   繁体   English

Windows 10 中批量重命名文件

[英]Batch rename files in Windows 10

I have a folder in which I need to rename all of the files to replace a string with another string:我有一个文件夹,我需要在其中重命名所有文件以用另一个字符串替换一个字符串:

File 01 (Something) ABC.txt ---> File 01 - ABC.txt
File 02 (Something) DEF.txt ---> File 02 - DEF.txt

In other words I need to replace (Somthing) with - .换句话说,我需要将(Somthing)替换为-

I tried the ren solution mentioned in this answer but I got The syntax of the command is incorrect .我尝试了此答案中提到的ren解决方案,但我得到了The syntax of the command is incorrect Here's what I tried:这是我尝试过的:

ren *(Something)* *-*

I was looking for a cmd approach but it looks like my needs can't be done with the ren command.我一直在寻找cmd方法,但看起来我的需求无法通过ren命令完成。

So I ended up just creating a simple PHP script based on this answer :所以我最终只是根据这个答案创建了一个简单的 PHP 脚本:

<?php
$path = 'E:/My Folder';
if ($handle = opendir($path)) {
    while (false !== ($fileName = readdir($handle))) {
        if(in_array($fileName, array('.', '..'))) {
            continue;
        }
        $newName = str_replace("(Something)", "-", $fileName);
        rename("{$path}/{$fileName}", "{$path}/{$newName}");
    }
    closedir($handle);
}
?>

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

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