How to prevent the filechooser resolving symblic links  
Author Message
Zoran Pjevic





PostPosted: 2004-9-15 20:45:00 Top

java-programmer, How to prevent the filechooser resolving symblic links Hello everybody

I am using a filechooser object to select files.

JFileChooser _fileChooser = new JFileChooser();
File[] selectedfiles = _fileChooser.getSelectedFiles();

for (int i =0 ; i < selectedfiles.length; i++) {
//path = selectedfiles[i].getCanonicalPath();
path = selectedfiles[i].getPath();
}

The _fileChooser.getSelectedFiles() returns already absolute path
names. So no matter if I call getPath or getCanocialPath I get the
abosolute path names.

But I want to display symbolic links as relative pathnames.

Is there a way to accomplish this?

Any help I will welcome.

Thanks in advance,
Zoran



 
John McGrath [TeamB]





PostPosted: 2004-9-21 10:22:00 Top

java-programmer >> How to prevent the filechooser resolving symblic links On 9/15/2004 at 8:45:04 AM, Zoran Pjevic wrote:

> I am using a filechooser object to select files.

> The _fileChooser.getSelectedFiles() returns already absolute path
> names. So no matter if I call getPath or getCanocialPath I get the
> abosolute path names.
>
> But I want to display symbolic links as relative pathnames.

Assuming that JFileChooser did return relative paths, it is not very clear
what directory the paths would be relative to. It could be the initial
current directory set on the JFileChooser, although that changes based on
user input and possibly based on other code behavior. It could also be
the current value of the "user.dir" system property or the operating
system's "current working directory", assuming that was defined.

> Is there a way to accomplish this?

I think you will need to write your own getPathRelativeTo(File, File)
method. Be aware that there are some tricky issues here. If there are
symbolic links (or other filesystem oddities) on your path, it may not be
too clear what relative path should be returned. It could return a path
containing the symbolic link, or one based on the canonical path for the
specified path. Also, you need to consider the possibility that there is
no possible relative path, but you probably just want to return an
absolute path in that case.

--
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html