This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
An IDE is no substitute for an Intelligent Developer.
Joined: Dec 19, 2001
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Simple "dir" command in DOS file structer JSP server via JSP page