Friday, May 11, 2007

How to get ?

I was trying to automate some of my manual work, I came across one problem. Is java providing any option by which if I give the file name and directory name it will go ahead and search that file in the given directory or sub-directory and return me the complete path of the file ? Unfortunately not :(, there is no direct API that can do this work for me. But Kannan told me that one can make a code which can recursively do this work. And he already had written some code for this. I was trying to tackle this problem with a different approach. The approach is something like:

On windows, dos gives me an option to search a file in a dir or sub-dir by command:
dir filename /s
Linux and Solaris gives me option of search the same by command: find /directory_name filename
So, why not using the runtime option of java system class and write a code like:

if ( OS == Windows) {get it by dir filename /s}
elseif (OS == Linux or Solaris or Unix){get it by find /directory_name filename}
else {God Knows only :)}
Right now I am not ready with code(because this dos is not giving anything directly, so need to remove useless things) but will come back soon with the results and the optimal code. Any suggestions are most welcome.


Bipin "3~" Upadhyay said...
This comment has been removed by the author.
Bipin "3~" Upadhyay said...

DOS provides search??? Really?
I couldn't do it using the ./s thingy provided by you.

On another note, did you try JavaFX?
I tried it on the very first day of launch (pure coincidence). Found it interesting. Yet to see the real usage.

Vaibhav said...

Ah Bipin thats for the correction, it was /s not ./s. I made the correction. Ya DOS is providing search facility and i use it very offen becasue my search of windows is now working :) and we often need to search for a file in directory or sub-dir.

Ya just read of JavaFX. Waiting for the guys to come back from JavaOne then they we will force them do give a big demo :). By the way I will look for it.

Bipin "3~" Upadhyay said...

I won't be able to devote time on JavaFX... pretty busy these days... would look forward to your post on the topic.

Coming back to your post... Yup! /s works.
I generally use the CUI on windows too, so initially I was pretty happy to have found the search flag. However, it seems to be slower than the GUI search. :(
This discovery really amazed me. This is something that only M$ can do. :)
I am also trying PowerShell, but haven;t been really satisfied so far. I guess I need to learn a little more about it.

Vaibhav said...

ya yesterday read something in details about JavaFX will post something soon :)