- Timestamp:
- 06/28/13 14:38:46 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-utils/src/main/java/de/ugoe/cs/util/FileTools.java
r1240 r1243 99 99 return (new String(buffer)).split(splitString); 100 100 } 101 102 /** 103 * <p> 104 * Autocompletes a give path. The path must be absolute. Otherwise, autocompletion 105 * is not possible. 106 * </p> 107 * 108 * @param prefix 109 * the prefix to be complete 110 * @return the auto completed path 111 */ 112 public static String autoCompletePath(String prefix) { 113 File prefixFile = new File(prefix); 114 File parentDir = prefixFile.getParentFile(); 115 116 if (parentDir == null) { 117 // the prefix does not denote a path or denotes one of the root directories. 118 // this can not be auto completed 119 return prefix; 120 } 121 122 String[] completions = null; 123 124 if (parentDir.exists()) { 125 completions = parentDir.list(); 126 } 127 128 if (completions == null) { 129 completions = new String[0]; 130 } 131 132 String completedPrefix; 133 134 completedPrefix = StringTools.autocomplete(prefixFile.getName(), completions); 135 136 File completedFile = new File(parentDir, completedPrefix); 137 138 if (completedFile.exists() && completedFile.isDirectory()) { 139 return completedFile.getAbsolutePath() + File.separator; 140 } 141 else { 142 return (parentDir.getAbsolutePath() + File.separator + completedPrefix) 143 .replaceAll("//", "/"); 144 } 145 } 101 146 102 147 }
Note: See TracChangeset
for help on using the changeset viewer.