My program has to watch for files which match a mask. The folder name and mask are passed through command line arguments. But the mask is replaced by the first match before I can use it!
Double quotes have no effect and other symbols too. I tried using \
or '
to protect the input. However then this symbol will be added to the args, which I do not want. Any idea of how to fix it?
public static void main(String[] args) throws IOException {
File dir = new File(args[0]);
String mask = args[1];
System.out.println(dir.getAbsolutePath());
System.out.println(mask);
String regex = args[2];
System.out.println(regex);
}
Regular expression from args[2]
also replaced with some file from folder.
Input: "E:\Programming\Java\Task7" *.??? ...
Ouput: E:\Programming\Java\Task7 .git Task7.iml
Input: "E:\Programming\Java\Task7" *.????* [a-zA-Z]
Output: E:\Programming\Java\Task7 .idea [a-zA-Z]
Input: "E:\Programming\Java\Task7" '.???' ...
Output: E:\Programming\Java\Task7 '.???' ...
Input: "E:\Programming\Java\Task7" \\'.???'\\ ...
Output: E:\Programming\Java\Task7 \'.???'\ ...
I understand that using quote or backslash isn't that bad idea, but I think there exists better way.