Reputation: 2184
I have a program where I have to take paths from the command line as input, likely with wildcards such as ?, * and **. Java persists in expanding these paths on it's own, usually screwing up.
For instance:
java -jar myapp.jar C:/Hello/World/*
Gives me a String[] args that looks like this:
["C:\Hello\World\foo", "C:\Hello\World\bar"]
Not only is this extremely troublesome, it also messes up the ** wildcard:
java -jar myapp.jar C:/Hello/World/**
Gives the same thing as before, when ** should be a recursive search. I have an algorithm for doing this efficiently, which I originally developed on python, but it's pointless if I can't use it. Is there a way to prevent this from happening?
EDIT = I tried using different shells (PowerShell, cmd, eclipse), using different formats (no quotes, quotes, double quotes) and none of them worked.
Upvotes: 0
Views: 191
Reputation: 206765
Java is not doing that, it's your shell.
Quote the arguments:
java -jar myapp.jar 'C:/Hello/World/**'
Or
java -jar myapp.jar "C:/Hello/World/**"
Upvotes: 5
Reputation: 573
This could be completely wrong, but try this:
java -jar myapp.jar C:/Hello/World/\*
Upvotes: 0