Y'all are a bunch of wankers!

java cli accepting file paths as parameters

ok, so one more stupid question and then Im done for a while.

I need to accept a path to a folder as one of the parameters on the cli.  I _really_ dont want to write the bit that chops it up unixy style myself, is there some standard java way of handling that kind of input?
Permalink Send private email zestyZucchini 
March 11th, 2007 3:36pm
You want to chop up the args array or the path?
Permalink Send private email a2800276 
March 11th, 2007 3:54pm
the path, Id like to allow for the standard wild cards and expansion behavior and so on.  its not _absolutely_ necessary, so if its gonna be a mission Ill leave it, but it feels like a Nice Thing To Do.
Permalink Send private email zestyZucchini 
March 11th, 2007 3:56pm
I do believe that Java has a standard way of handling the path separators and forward/backward slashes.

No, I don't remember how it works, just that I think it does.
Permalink Send private email Aaron F Stanton 
March 11th, 2007 4:00pm
you would create a java.io.File (http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html) from the String that's passed in and then use File's methods to access the different components of the path. Wildcards and stuff are usually handled by the shell if you're passing them in via cli and I'm not aware of any standard java libs for globbing etc.
Permalink Send private email a2800276 
March 11th, 2007 4:08pm
ok, cool.  thats what Im doing so I guess Ill leave it.

for some reason I had always assumed that the programs themselves were handling the expansion & wildcards, dunno why..silly now I think about it...
Permalink Send private email zestyZucchini 
March 11th, 2007 4:09pm
Is there a way to make File step through the components of a path?  /usr/incude/crap/under/here ....
Permalink zed 
March 11th, 2007 4:20pm
you can step backwards using .parent and receiving a File with that file system object, if you want to do the other way though Im not sure how you would do it, except that it probably involves using the path separate provided by the File pbject and string manipulation.

Cocoa has some lovely builtin stuff for walking file paths in that way. ::sigh::
Permalink Send private email zestyZucchini 
March 11th, 2007 4:26pm
There also StringTokenizer if all you care about are the names of the directory.
Permalink Send private email a2800276 
March 11th, 2007 4:29pm
ah, nice.  so you could pass File.pathSeparator into that.
Permalink Send private email zestyZucchini 
March 11th, 2007 4:40pm

This topic is archived. No further replies will be accepted.

Other topics: March, 2007 Other topics: March, 2007 Recent topics Recent topics