root directory of the machine

A

autogoor

Hi, I am writing a "Window-Explorer-Like" file explorer with JTree. I
would like the root of the tree to be the highest directory on the
machine. For windows, it is "Desktop", which includes "My Documents",
"My Computer", "My network place", ... etc, as sub directory. On Unix,
I would like to start with "username". How can I get such root
directory by java?

Thanks,

autogoor
 
D

Dotty

Hi, I am writing a "Window-Explorer-Like" file explorer with JTree. I
would like the root of the tree to be the highest directory on the
machine. For windows, it is "Desktop", which includes "My Documents",
"My Computer", "My network place", ... etc, as sub directory. On Unix,
I would like to start with "username". How can I get such root
directory by java?

Thanks,

autogoor

There is a java method to find the root, just search for it.
But, on WINDOES, there is one root for each partition on each disk.
For example "C:\", "D:\" etc. "Desktop" is not the root.
There is one desktop directory for each user. For example:
"C:\Documents and Settings\Dotty\Desktop"
 
A

Aquila Deus

Hi, I am writing a "Window-Explorer-Like" file explorer with JTree. I
would like the root of the tree to be the highest directory on the
machine. For windows, it is "Desktop", which includes "My Documents",
"My Computer", "My network place", ... etc, as sub directory. On Unix,
I would like to start with "username". How can I get such root
directory by java?

"My Computer" is not the root, and "My Documents" is not even the home
directory for each user. They're provided just for newbie's
convenience. If you want to emulate them under unix, you have to know
the user's desktop environment first.
 
P

Paul van Rossem

Hi, I am writing a "Window-Explorer-Like" file explorer with JTree. I
would like the root of the tree to be the highest directory on the
machine. For windows, it is "Desktop", which includes "My Documents",
"My Computer", "My network place", ... etc, as sub directory. On Unix,
I would like to start with "username". How can I get such root
directory by java?

Thanks,

autogoor


There is a java method to find the root, just search for it.
But, on WINDOES, there is one root for each partition on each disk.
For example "C:\", "D:\" etc. "Desktop" is not the root.
There is one desktop directory for each user. For example:
"C:\Documents and Settings\Dotty\Desktop"
[/QUOTE]
WIndows is really confusing in this respect. Although "Desktop" is
"physically" (in the file structure) located as Dotty explained in a
branch separately for every user, it is presented, when browsing, as the
root node, above the roots for all partitions.
This makes the Desktop very ambiguous and makes the tree a cyclical
thing (which is then not a "tree" anymore). So you have to distinguish
the file structure on disk (which is actually a set of trees, one for
each partition, with subtrees per user) from its visual presentation,
which merges the partition trees in a very strange way.
So. if you are writing an "Window-Explorer-Like" file explorer with
JTree, you must first decide /which tree/ you want to implement.
Hope this helps, Paul.
 
A

autogoor

It seems to me that I should use the "virtual Root", what the java
method to get that? Also, what is the java method to get the root on
Unix? If I search, what is the key word?

Thanks

autogoor

There is a java method to find the root, just search for it.
But, on WINDOES, there is one root for each partition on each disk.
For example "C:\", "D:\" etc. "Desktop" is not the root.
There is one desktop directory for each user. For example:
"C:\Documents and Settings\Dotty\Desktop"
WIndows is really confusing in this respect. Although "Desktop" is
"physically" (in the file structure) located as Dotty explained in a
branch separately for every user, it is presented, when browsing, as the
root node, above the roots for all partitions.
This makes the Desktop very ambiguous and makes the tree a cyclical
thing (which is then not a "tree" anymore). So you have to distinguish
the file structure on disk (which is actually a set of trees, one for[/QUOTE]
 
O

Oscar kind

It seems to me that I should use the "virtual Root", what the java
method to get that? Also, what is the java method to get the root on
Unix? If I search, what is the key word?

Depends on your strategy. You could use new File("/"), for example, but
then your program won't work on Windows (as / is the unix/linux file
system root).

My prerefence is to pretend not to know that the root of the filesystem
on linux/unix is "/", and on windows "A:", "B:", "C:", etc. So I use a
static method on the File class:
File#listRoots()

This method returns an array of File instances that denote the root's of
the file system. On lunix, you'll get an array of size one, with a File
object representing "/".
 
A

Aquila Deus

It seems to me that I should use the "virtual Root", what the java
method to get that?

The desktop and document folder are determined by user's desktop
environment. Java provides no support for this. However, you can use
environment variables to get related info. On windows USERPROFILE
points to the user's home directory, but you can't know the exact paths
to desktop and "my documents" (they may be changed due to different
language version of windows or by the user himself)
Also, what is the java method to get the root on
Unix? If I search, what is the key word?

just "/".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,113
Latest member
Vinay KumarNevatia
Top