1

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 -.

I tried the ren solution mentioned in this answer but I got The syntax of the command is incorrect. Here's what I tried:

ren *(Something)* *-*
Compo
  • 36,585
  • 5
  • 27
  • 39
dokgu
  • 4,957
  • 3
  • 39
  • 77

1 Answers1

1

I was looking for a cmd approach but it looks like my needs can't be done with the ren command.

So I ended up just creating a simple PHP script based on this answer:

<?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);
}
?>
dokgu
  • 4,957
  • 3
  • 39
  • 77