Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.nio.file.Path;
- import java.util.ArrayList;
- import java.util.List;
- public class FileNameReplacer {
- public static void main(String[] args) {
- File f = new File("C:\\Users\\Public\\Operational_Functional_Block\\src\\Data");
- List<String> results = new ArrayList<>();
- File[] files = f.listFiles();
- for (File file : files) {
- if (file.isFile()) {
- results.add(file.getName());
- }
- }
- for (int x = 0; x < f.list().length; x++) {
- String stringToBeReplaced = "obf.reg";
- String stringReplacement = "obf_rex";
- if ((results.get(x)).startsWith("obf.reg")) {
- // ----------------------------------------------
- String pathAsAString1 = f + "\\" + results.get(x);
- Path path1 = Path.of(pathAsAString1);
- File path1A = new File(String.valueOf(path1));
- // ----------------------------------------------
- String pathAsAStringA2 = f + "\\" + results.get(x);
- String pathAsAStringB2 = pathAsAStringA2.replace(stringToBeReplaced, stringReplacement);
- Path path2 = Path.of(pathAsAStringB2);
- File path2A = new File(String.valueOf(path2));
- // ----------------------------------------------
- path1A.renameTo(path2A);
- }
- }
- System.out.println("Done!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment