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:ProgrammingJavaTask7" *.??? ...
Ouput: E:ProgrammingJavaTask7 .git Task7.iml
Input: "E:ProgrammingJavaTask7" *.????* [a-zA-Z]
Output: E:ProgrammingJavaTask7 .idea [a-zA-Z]
Input: "E:ProgrammingJavaTask7" '.???' ...
Output: E:ProgrammingJavaTask7 '.???' ...
Input: "E:ProgrammingJavaTask7" \'.???'\ ...
Output: E:ProgrammingJavaTask7 '.???' ...
I understand that using quote or backslash isn't that bad idea, but I think there exists better way.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…