This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes Simple Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Simple "dir" command in DOS file structer JSP server via JSP page" Watch "Simple "dir" command in DOS file structer JSP server via JSP page" New topic
Author

Simple "dir" command in DOS file structer JSP server via JSP page

Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
I've done some searches here and on google for information about this.
It seems, in general, that there is no way to return a "dir" query back to where it was called. There is much information on program execution, but whenever the "dir" command is mentioned, the thread stops with no solutions.
......
On a side note, the reason why I want to get the results of "dir" is so that I can design my own JSP displayed file system for a project I have been working on. I figure that with the results, I can parse out directories and file names. If there is an easier way to do this, I am, of course, definitely open to them. But for now this is the most straight foreward way I could think of.
Either way, I'd like to know how to get the result of "dir" back.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
Actually it will be much easier to use java.io.File to get the contents of a directory. With File.list() you can use a FileNameFilter for example.
Bill
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16091
    
  21

As William mentioned, the java.io.File class provides much tidier ways of running through a filesystem - plus the results aren't dependent on the OS and any convironmental command options.
Just for the sake of saying so, I think that you'd have to use java.lang.System.setOut() to redirect the VM's standard output stream, then do a Runtime.exec to execute the "dir" command. The problem is, this would possibly collide with other threads in the same VM also writing to stdout.
But it's not worth the trouble of researching in-depth just to get a directory listing.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
Great, thanks for the suggestion to use java.io.File.
I have toyed with it a little now and have the directory/file structure established.
Thanks for the help.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Simple "dir" command in DOS file structer JSP server via JSP page