import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Collectors;
String glob = "glob:" + parentDir.toString() + File.separator
+ rest;
PathMatcher pm = FileSystems.getDefault().getPathMatcher(glob);
- int maxDepth = rest.contains("**") ? Integer.MAX_VALUE
+ int maxDepth = rest.contains("**") ? 1028
: (int) (rest.chars()
.filter(ch -> ch == File.separatorChar).count())
+ 1;
+
Files.walkFileTree(parentDir,
EnumSet.of(FileVisitOption.FOLLOW_LINKS), maxDepth,
new SimpleFileVisitor<Path>()
files.add(f);
}
}
+ Collections.sort(files);
return files;
}
}
/*
- * This method returns the basename of the first --open or --opennew value.
- * Used primarily for substitutions in output filenames.
+ * This method returns the basename of File file
*/
public static String getBasename(File file)
{
+ return getBasenameOrExtension(file, false);
+ }
+
+ /*
+ * This method returns the extension of File file.
+ */
+ public static String getExtension(File file)
+ {
+ return getBasenameOrExtension(file, true);
+ }
+
+ public static String getBasenameOrExtension(File file, boolean extension)
+ {
if (file == null)
return null;
- String basename = null;
+ String value = null;
String filename = file.getName();
int lastDot = filename.lastIndexOf('.');
if (lastDot > 0) // don't truncate if starts with '.'
{
- basename = filename.substring(0, lastDot);
+ value = extension ? filename.substring(lastDot + 1)
+ : filename.substring(0, lastDot);
}
else
{
- basename = filename;
+ value = extension ? "" : filename;
}
- return basename;
+ return value;
}
/*
- * This method returns the dirname of the first --open or --opennew value.
+ * This method returns the dirname of the first --append or --open value.
* Used primarily for substitutions in output filenames.
*/
public static String getDirname(File file)
String dirname = null;
try
{
- dirname = file.getParentFile().getCanonicalPath();
+ File p = file.getParentFile();
+ File d = new File(substituteHomeDir(p.getPath()));
+ dirname = d.getCanonicalPath();
} catch (IOException e)
{
Console.debug(