Improved not exist file case.

This commit is contained in:
Christian P. MOMON 2021-04-26 19:53:41 +02:00
parent 25e0fb5f64
commit bb25cfa96d
2 changed files with 75 additions and 42 deletions

View file

@ -393,11 +393,22 @@ public final class Logar
*/ */
public static void checkLogFiles(final File source) public static void checkLogFiles(final File source)
{ {
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName(); if (source == null)
for (File file : files)
{ {
checkLogFile(file); System.out.println("Undefined source.");
}
else if (source.exists())
{
System.out.println("Missing source to check.");
}
else
{
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName();
for (File file : files)
{
checkLogFile(file);
}
} }
} }
@ -410,11 +421,22 @@ public final class Logar
*/ */
public static void checkSort(final File source) throws IOException public static void checkSort(final File source) throws IOException
{ {
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName(); if (source == null)
for (File file : files)
{ {
checkSortFile(file); System.out.println("Undefined source.");
}
else if (source.exists())
{
System.out.println("Missing source to check.");
}
else
{
Files files = FilesUtils.search(source, LOGFILE_PATTERN).sortByName();
for (File file : files)
{
checkSortFile(file);
}
} }
} }
@ -483,12 +505,23 @@ public final class Logar
*/ */
public static void sort(final File source) throws IOException public static void sort(final File source) throws IOException
{ {
Files files = FilesUtils.searchEndingWith(source, LOGFILE_PATTERN).removeHidden().sortByName(); if (source == null)
for (File file : files)
{ {
System.out.println("== Sort for [" + file.getName() + "]"); System.out.println("Undefined source.");
LogFile.sortLogFile(file); }
else if (source.exists())
{
System.out.println("Missing source to sort.");
}
else
{
Files files = FilesUtils.searchEndingWith(source, LOGFILE_PATTERN).removeHidden().sortByName();
for (File file : files)
{
System.out.println("== Sort for [" + file.getName() + "]");
LogFile.sortLogFile(file);
}
} }
} }

View file

@ -48,7 +48,7 @@ public class FilesUtils
Files result; Files result;
result = new Files(); result = new Files();
if (source != null) if ((source != null) && (source.exists()))
{ {
if (source.isFile()) if (source.isFile())
{ {
@ -74,34 +74,6 @@ public class FilesUtils
return result; return result;
} }
/**
* List recursively.
*
* @param source
* the source
* @param extensions
* the extensions
* @return the files
*/
public static Files searchEndingWith(final File source, final String... extensions)
{
Files result;
result = new Files();
Files full = listRecursively(source);
for (File file : full)
{
if (StringUtils.endsWithAny(file.getName(), extensions))
{
result.add(file);
}
}
//
return result;
}
/** /**
* Search recursively. * Search recursively.
* *
@ -131,4 +103,32 @@ public class FilesUtils
// //
return result; return result;
} }
/**
* List recursively.
*
* @param source
* the source
* @param extensions
* the extensions
* @return the files
*/
public static Files searchEndingWith(final File source, final String... extensions)
{
Files result;
result = new Files();
Files full = listRecursively(source);
for (File file : full)
{
if (StringUtils.endsWithAny(file.getName(), extensions))
{
result.add(file);
}
}
//
return result;
}
} }