Advertisement
Guest User

ntfs83Java

a guest
Oct 16th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. /** Stuff to make ntfs 8.3 dirs by Jorge Chayan **/
  2.  
  3. public static String toNTFS83(File dir)
  4. {
  5.     StringBuilder wholedir = new StringBuilder(dir.getAbsolutePath());
  6.     if (wholedir.length() <= 8) return wholedir.toString();
  7.     else {
  8.         String disk = "";
  9.         for (char i = 'A'; i <= 'Z'; i++) {
  10.             if (wholedir.toString().contains(i + ":\\")) {
  11.                 disk = wholedir.substring(0, 3);
  12.                 System.out.println(disk);
  13.                 wholedir.delete(0, 3);
  14.                 System.out.println(wholedir.toString());
  15.                 break;
  16.             }
  17.         }
  18.         int end = wholedir.indexOf("\\");
  19.         StringBuilder dirs = new StringBuilder("");
  20.         int point = dir.getName().indexOf(".");
  21.         String xtens = "";
  22.         if (point != -1) xtens = dir.getName().substring(point, dir.getName().length());
  23.             while (true) {
  24.             String aux;
  25.             if (end == -1) {
  26.                 if (point != -1) aux = dir.getName().substring(0, point);
  27.                 else aux = dir.getName();
  28.             }
  29.             else aux = wholedir.substring(0, end);
  30.             System.out.println(aux);
  31.             wholedir.delete(0, end + 1);
  32.             System.out.println(wholedir.toString());
  33.             if (aux.length() >= 8) {
  34.                 if (aux.contains("" + ((char) 91))) aux.replace((char) 91, '_');
  35.                 if (aux.contains("" + ((char) 47))) aux.replace((char) 47, '_');
  36.                 for (char j = 0; j < 32; j++) {
  37.                     if (aux.contains("" + j)) aux.replace(j, '_');
  38.                 }
  39.                 for (char j = 33; j < 46; j++) {
  40.                     if (aux.contains("" + j)) aux.replace(j, '_');
  41.                 }
  42.                 if (end != -1 && aux.contains("" + ((char) 46))) aux.replace((char) 46, '_');
  43.                 for (char j = 58; j < 65; j++) {
  44.                     if (aux.contains("" + j)) aux.replace(j, '_');
  45.                 }
  46.                 for (char j = 93; j < 97; j++) {
  47.                     if (aux.contains("" + j)) aux.replace(j, '_');
  48.                 }
  49.                 for (char j = 123; j < 128; j++) {
  50.                     if (aux.contains("" + j)) aux.replace(j, '_');
  51.                 }
  52.  
  53.                 int limit = 6;
  54.                 for (int k = 0; k < limit; k++) {
  55.                     if (aux.charAt(k) != ' ') {
  56.                         dirs.append(aux.charAt(k));
  57.                     }
  58.                     else limit++;
  59.                 }
  60.                 dirs.append("~1");
  61.                 if (end != -1) dirs.append("\\");
  62.             }
  63.             else dirs.append(aux + "\\");
  64.             if (end == -1) break;
  65.             end = wholedir.indexOf("\\");
  66.         }
  67.         return disk.toUpperCase() + dirs.toString().toUpperCase() + xtens.toUpperCase();
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement