42 import java.io.FileNotFoundException;
43 import java.io.IOException;
44 import java.nio.file.Files;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
47 import java.nio.file.StandardCopyOption;
48 import java.util.ArrayList;
50 import okw.exceptions.OKWDirectoryDoesNotExistsException;
51 import okw.exceptions.OKWDirectorySeperatorNotImplementedException;
52 import okw.exceptions.OKWFileDoesNotExistsException;
53 import okw.log.Logger_Sngltn;
114 Boolean lvbReturn =
false;
121 File myDirectory =
new File( fpsPath );
124 if ( myDirectory.exists() & myDirectory.isDirectory() )
128 else if ( myDirectory.exists() & myDirectory.isFile() )
134 myDirectory.mkdirs();
170 String lvsPath = Path;
171 Boolean lvbReturn =
false;
181 File myPath =
new File( lvsPath );
183 if ( myPath.exists() )
185 for ( File f : myPath.listFiles() )
187 if ( f.isDirectory() )
224 Boolean lvbReturn =
false;
233 File myFile =
new File( fpsPaFiNa );
236 if ( myFile.exists() )
239 if ( myFile.isDirectory() )
244 else if ( myFile.isFile() )
263 public static void copyDirectory( String fpsSourceFolder, String fpsDestinationFolder )
266 File sourceFolder =
new File( fpsSourceFolder );
269 File destinationFolder =
new File( fpsDestinationFolder );
271 copyDirectory( sourceFolder, destinationFolder );
275 private static boolean copyDirectory( File fpSourceFolder, File fpDestinationFolder )
278 Boolean lvbReturn =
false;
286 Log.
LogFunctionStartDebug(
"OKW_FileHelper.DirectoryMove",
"fpSourceFolder", fpSourceFolder.getPath(),
"fpDestinationFolder",
287 fpDestinationFolder.getPath() );
292 if ( fpSourceFolder.isDirectory() )
296 if ( !fpDestinationFolder.exists() )
298 fpDestinationFolder.mkdir();
299 System.out.println(
"Directory created :: " + fpDestinationFolder );
303 String files[] = fpSourceFolder.list();
307 for ( String file : files )
309 File srcFile =
new File( fpSourceFolder, file );
310 File destFile =
new File( fpDestinationFolder, file );
313 copyDirectory( srcFile, destFile );
319 Files.copy( fpSourceFolder.toPath(), fpDestinationFolder.toPath(), StandardCopyOption.REPLACE_EXISTING );
320 System.out.println(
"File copied :: " + fpDestinationFolder );
323 catch (IOException e)
347 public static boolean moveDirectory( String fpsPaNaSource, String fpsPaNaDestination )
throws IOException, FileNotFoundException
349 Boolean lvbReturn =
false;
351 String lvsPaNaSource = fpsPaNaSource;
352 String lvsPaNaDestination = fpsPaNaDestination;
360 Log.
LogFunctionStartDebug(
"OKW_FileHelper.DirectoryMove",
"fpsPaNaSource", fpsPaNaSource,
"fpsPaNaDestination", fpsPaNaDestination );
368 copy( lvsPaNaSource, lvsPaNaDestination,
true );
384 public static void copy( String fpsSource, String fpsDestination, Boolean copySubDirs )
throws IOException, FileNotFoundException
386 Path lvSourcePath = Paths.get( fpsSource );
387 Path lvDestinationPath = Paths.get( fpsDestination );
389 if ( Files.notExists( lvSourcePath ) )
391 throw new FileNotFoundException(
"Source directory does not exist or could not be found: " + fpsSource );
397 Files.copy( lvSourcePath, lvDestinationPath );
406 public static ArrayList<File>
ListFiles( String fpsPath )
408 ArrayList<File> lvReturn =
new ArrayList<File>();
410 File root =
new File( fpsPath );
411 File[] list = root.listFiles();
417 for ( File f : list )
419 if ( f.isDirectory() )
421 System.out.println(
" Dir:" + f.getAbsolutePath() );
426 String myPathy = f.getAbsolutePath();
466 File myDir =
new File( fpsPaFiNa );
467 File[] listOfFiles = myDir.listFiles();
469 for ( File myFileToDelete : listOfFiles )
471 if ( !myFileToDelete.isDirectory() )
473 myFileToDelete.delete();
498 Boolean lvbReturn =
false;
506 File myFile =
new File( fpsPaFiNa );
508 lvbReturn = myFile.delete();
535 Boolean lvbReturn =
false;
541 File myFile =
new File( fpsPaFiNa );
544 if ( myFile.exists() )
547 if ( myFile.isFile() )
552 else if ( myFile.isDirectory() )
589 public static Boolean
isFile( String PATH )
592 Boolean lvbReturn =
false;
598 File myFile =
new File( PATH );
601 if ( myFile.exists() )
604 if ( myFile.isFile() )
637 public static void move( String fpsPaFiNaSource, String fpsPaFiNaDestination )
throws IOException, FileNotFoundException
640 Log.
LogFunctionStartDebug(
"OKW_FileHelper.Move",
"fpsPaFiNaSource", fpsPaFiNaSource,
"fpsPaFiNaDestination", fpsPaFiNaDestination );
647 copy( fpsPaFiNaSource, fpsPaFiNaDestination,
true );
676 public static boolean createFile( String fpsPaFiNa )
throws IOException
679 Boolean lvbReturn =
false;
681 Path newFilePath = Paths.get( fpsPaFiNa );
686 if ( !Files.exists( newFilePath ) )
688 Files.createFile( newFilePath );
730 Boolean lvbReturn =
false;
736 lvbReturn = Paths.get( PATH ).toFile().listFiles().length == 0;
780 String lvsReturn = fpsPath;
786 String myFileSeparator = System.getProperty(
"file.separator" );
788 if (
"/".equals( myFileSeparator ) )
790 lvsReturn = fpsPath.replace(
"\\",
"/" );
792 else if (
"\\".equals( myFileSeparator ) )
794 lvsReturn = fpsPath.replace(
"/",
"\\" );
799 lvsReturn = lvsReturn.replace(
"\\C:",
"C:" );
831 File myFile =
new File( PATH );
837 org.apache.commons.io.FileUtils.forceMkdir( myFile );