[go: up one dir, main page]

Menu

[1df0c4]: / FileRenamer.java  Maximize  Restore  History

Download this file

39 lines (35 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package filestudio;
import java.io.File;
import java.util.List;
/**
*
* @author Admin
*/
public class FileRenamer {
public FileRenamer(){
}
public String removeWordFromList(List<File> fileList, String ReplaceFrom, String ReplaceWith)
{
File[] filesList = {};
//filesList = new ArrayList<File>(fileList);
filesList = fileList.toArray(filesList);
try
{
// This method will rename all files in a folder by chaning ReplaceFrom string with ReplaceWith string
for (int i=0; i< filesList.length; i++)
{
String newName= (filesList[i].toString().replaceAll(ReplaceFrom, ReplaceWith)).trim();
filesList[i].renameTo(new File(newName));
}
return "Successfully renamed "+filesList.length+" files.";
}
catch (Exception e)
{
return (e.getMessage());
}
}
}