MAKS_Enjoyer

FileNameReplacer™®

Nov 13th, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | Source Code | 0 0
  1. import java.io.File;
  2. import java.nio.file.Path;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class FileNameReplacer {
  7.     public static void main(String[] args) {
  8.         File f = new File("C:\\Users\\Public\\Operational_Functional_Block\\src\\Data");
  9.         List<String> results = new ArrayList<>();
  10.         File[] files = f.listFiles();
  11.         for (File file : files) {
  12.             if (file.isFile()) {
  13.                 results.add(file.getName());
  14.             }
  15.         }
  16.         for (int x = 0; x < f.list().length; x++) {
  17.             String stringToBeReplaced = "obf.reg";
  18.             String stringReplacement = "obf_rex";
  19.             if ((results.get(x)).startsWith("obf.reg")) {
  20.                 // ----------------------------------------------
  21.                 String pathAsAString1 = f + "\\" + results.get(x);
  22.                 Path path1 = Path.of(pathAsAString1);
  23.                 File path1A = new File(String.valueOf(path1));
  24.                 // ----------------------------------------------
  25.                 String pathAsAStringA2 = f + "\\" + results.get(x);
  26.                 String pathAsAStringB2 = pathAsAStringA2.replace(stringToBeReplaced, stringReplacement);
  27.                 Path path2 = Path.of(pathAsAStringB2);
  28.                 File path2A = new File(String.valueOf(path2));
  29.                 // ----------------------------------------------
  30.                 path1A.renameTo(path2A);
  31.             }
  32.         }
  33.         System.out.println("Done!");
  34.     }
  35. }
Tags: Java
Advertisement
Add Comment
Please, Sign In to add comment