0

I've got a list of files:

"f1.txt" "f2.txt" "f3.txt" "f4.txt"

and want to batch rename to:

"file1.txt" "file2.txt" "file3.txt" "file4.txt"

Ideally I would like to do this as a little java program but don't mind it being done in something like Windows PowerShell.

Thanks in advance

Lee

Hoyesic
  • 53
  • 1
  • 1
  • 5

2 Answers2

0

Just buil a function that get two parametrs oldname,and newname and put it inside

 // File  with old name
        File file = new File("oldname");

        // File  with new name
        File file2 = new File("newname");
        if(file2.exists()) throw new java.io.IOException("file exists");

        // Rename file 
        boolean success = file.renameTo(file2);
        if (!success) {

        }
    java.io.FileWriter out= new java.io.FileWriter(file2, true );//append=yes 
Vladimir Potapov
  • 2,347
  • 7
  • 44
  • 71
0

Powershell, will rename all files in $path:

$path = "C:\pathToFiles"
cd $path
ls | % { Rename-Item $_.Name $_.Name.replace("f","file") }
Raf
  • 9,681
  • 1
  • 29
  • 41