wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Identifying if a File is a Softlink. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Identifying if a File is a Softlink." Watch "Identifying if a File is a Softlink." New topic
Author

Identifying if a File is a Softlink.

Parth Bhatt
Ranch Hand

Joined: Oct 19, 2005
Posts: 58
Hi Ranchers,

I am looking for a way to identify if a disk file, represented by an object of the File class, is a softlink or not.

Basically, I am working on a File Search utility that recursively browses the file structure on a unix machine to find a file with a particular name. The Problem that i am facing is with softlinks. i.e. my prog enters into an infinite loop when it encounters a softlink. For e.g. if a softlink /root/.openoffice/user/work points to /root directory, my program would enter into an infinite loop as everytime it encoulters /root/.openoffice/user/work it sould actually get into /root directory.

If some one can provide a solution or a web-link that throws some ligt on this issue... Thanks is advance...

Regards,
Parth Bhatt


If your new Big Idea doesn't scare the hell out of you, <br />it's probably not a "new Big Idea".
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
The JConfig library can do this.

Interestingly, on OS X, the File.isFile and isDirectory methods report that a link to a directory is a directory, while an alias to a directory is a file. Quite confusing.
[ May 09, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Parth Bhatt
Ranch Hand

Joined: Oct 19, 2005
Posts: 58
Thanks Ulf...!!

JConfig seems to be great...

Since my requirement is only to find out if a file is a SoftLink or not, i wrote a /* bit lame */ piece of code, which works as follows :



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Identifying if a File is a Softlink.