| | 314 | |
|---|
| | 315 | /** |
|---|
| | 316 | * Returns a list of file names within a specific directory |
|---|
| | 317 | * |
|---|
| | 318 | * @param xmlDirectory specific directory |
|---|
| | 319 | * @return String[] list of file names |
|---|
| | 320 | */ |
|---|
| | 321 | public static String[] getFilesInDirectory(String xmlDirectory) |
|---|
| | 322 | { |
|---|
| | 323 | File dir = new File(xmlDirectory); |
|---|
| | 324 | |
|---|
| | 325 | return dir.list(); |
|---|
| | 326 | } |
|---|
| | 327 | |
|---|
| | 328 | public static File[] getFilesInDirectory(String directoryName, final String[] fileExtensions) |
|---|
| | 329 | { |
|---|
| | 330 | File directory = new File(directoryName); |
|---|
| | 331 | |
|---|
| | 332 | File[] files = directory.listFiles(new FilenameFilter() |
|---|
| | 333 | { |
|---|
| | 334 | public boolean accept(File dir, String name) |
|---|
| | 335 | { |
|---|
| | 336 | for(String currFileExtension:fileExtensions) |
|---|
| | 337 | { |
|---|
| | 338 | return name.endsWith(currFileExtension); |
|---|
| | 339 | } |
|---|
| | 340 | return false; |
|---|
| | 341 | } |
|---|
| | 342 | }); |
|---|
| | 343 | return files; |
|---|
| | 344 | } |
|---|
| | 345 | |
|---|
| | 346 | /** |
|---|
| | 347 | * Returns the file name without an extension or directory path |
|---|
| | 348 | * @param filepath path to the file |
|---|
| | 349 | * @return String file name without an extension or directory path |
|---|
| | 350 | */ |
|---|
| | 351 | public static String getFilenameWithoutExtension(String filepath) |
|---|
| | 352 | { |
|---|
| | 353 | String filename = filepath; |
|---|
| | 354 | int index = filename.lastIndexOf("/"); |
|---|
| | 355 | int index2 = filename.lastIndexOf("\\"); |
|---|
| | 356 | |
|---|
| | 357 | if(index2 > index) |
|---|
| | 358 | { |
|---|
| | 359 | index = index2; |
|---|
| | 360 | } |
|---|
| | 361 | |
|---|
| | 362 | if(index>-1) |
|---|
| | 363 | { |
|---|
| | 364 | filename = filename.substring(index+1); |
|---|
| | 365 | } |
|---|
| | 366 | |
|---|
| | 367 | index = filename.lastIndexOf("."); |
|---|
| | 368 | |
|---|
| | 369 | if(index > -1) |
|---|
| | 370 | { |
|---|
| | 371 | filename = filename.substring(0,index); |
|---|
| | 372 | } |
|---|
| | 373 | |
|---|
| | 374 | return filename; |
|---|
| | 375 | } |
|---|
| | 376 | |
|---|
| | 377 | /** |
|---|
| | 378 | * Adds slashes if needed to a file directory |
|---|
| | 379 | * @param fileDirectory file directory path |
|---|
| | 380 | * @return String formatted file directory path |
|---|
| | 381 | */ |
|---|
| | 382 | public static String formatDirectoryName(String fileDirectory) |
|---|
| | 383 | { |
|---|
| | 384 | if(!(fileDirectory.endsWith("/")||fileDirectory.endsWith("\\"))) |
|---|
| | 385 | { |
|---|
| | 386 | fileDirectory+="/"; |
|---|
| | 387 | } |
|---|
| | 388 | return fileDirectory; |
|---|
| | 389 | } |
|---|