This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic