|
|||||
|
|
#11 |
|
|
> No this is not homework . let me make this a bit more specefic. > my project is very simliar to a two level directory structures with > multiple files at each level. Can you clarify something please ? It's not clear whether you are using the file/directory structure that is used to organise file-systems as an /example/ or not. It seems that the people who have replied so far are all ***uming that you want to create a structure that mimics the specifics of the actual files you have on your C: drive. Maybe they are right, but I am wondering if you just mean that you want to know how to build a tree structure (with additional data), and are just using the file/directory hierarchy as an example of the kind of structure you want to build. -- chris |
|
|
#12 |
|
|
> michael wrote: > > However you feel about this reply, you need to realize also that people will > come out of the woodwork to help you if you will post some code. the actual code that I have developed is too long to post. and the problem is to complex to state here. its not difficult to traverse a tree ( 2 levels !) , the difficult task is to initailte a process one a node has reached a limit. for example if ( directory[0].file[10].size > 10000 ) { // archive , load to db , etc.. asociated with above }; thanks Michael |
|
|
#13 |
|
|
> michael wrote: > > > No this is not homework . let me make this a bit more specefic. > to build a tree structure (with additional data), and are just using the > file/directory hierarchy as an example of the kind of structure you want > to build. > > -- chris yes chris , the directory hierarchy is used as an example. ok this is the real structure : cl*** groups { int size; String Name; String networkname; String Capacity; String [] files; cl*** files { int size; String Name; String Capacity; } then an array of groups will define an structure similiar to a two level diretory file system. thanks Michael } |
|
|
#14 |
|
|
michael wrote:
<snip> > then an array of groups will define an structure similiar to a two > level > diretory file system. So I must be a doofus after all. Given that file and directory (read: filesystem) manipulation is already provided by the java.io.File cl***, why would you want to re-invent the wheel?! You can find the parent directory of any file, list all files in a directory (hint: invoke isDirectory() first), obtain file size, get access time, etc. IOW you've already got the view of the underlying model. What are you trying to accomplish by adding a custom veneer? |
|
|
#15 |
|
|
michael wrote:
> Paul Lutus <nospam@nosite.zzz> wrote in message > news:<10jmabu5pm1hnf2@corp.supernews.com>... >> michael wrote: >> >> However you feel about this reply, you need to realize also that people >> will come out of the woodwork to help you if you will post some code. > > > the actual code that I have developed is too long to post. It shouldn't be, which is why you should post the simplest working, compilable version of your algorithm, then ask for help. > and the > problem is to complex to state here. This is definitely not true. The actual solution to your problem, suitable for recording an entire directory tree in your own tree, can be expressed in 25 lines of code. > > its not difficult to traverse a tree ( 2 levels !) , the difficult > task is to initailte a process one a node has reached a limit. Once you have defined "limit" suitably, that is not difficult at all, to any number of filesystem levels, but it is not part of your original problem statement. In any case, if you believe traversing a two-ply tree is not difficult, then post your code. > for example > > if ( directory[0].file[10].size > 10000 ) { > // archive , load to db , etc.. asociated with above > }; You are adding conditions to your original problem statement. Nevertheless, it is not difficult. Please take my earlier advice -- start by solving the simplest version of the problem, and begin to read about recursion. -- Paul Lutus http://www.arachnoid.com |
|
|
#16 |
|
|
michael wrote:
> cl*** groups { > int size; > String Name; > String networkname; > String Capacity; > String [] files; > > cl*** files { > int size; > String Name; > String Capacity; > } > > then an array of groups will define an structure similiar to a two > level diretory file system. BTW, it is almost universal to give cl***es names that are singular and start with a capital letter -- I /strongly/ recommend that you change the names to Group and File. Similarly, it is preferred to use lower-case names for ordinary fields, hence "name" and "capacity", not "Name" and "Capacity". I'll use the preferred forms in the rest of this post. I'm not really clear on what you are asking, so this may be irrelevant. Is there any reason you hold an array of String names of "files" in your groups" ? To me it would seem more natural for each Group to hold an array f Files. Actually a java.util.List of some kind, probably a java.util.ArrayList, would be better still. If you don't do that then you'll have difficulty mapping from the String filenames to the actual files -- the natural approach of using a java.util.HashMap won't work without a lot of added complication because the Files' names are not necessarily unique (presumably the same name can be used for two Files in different Groups). If you make that change, then it'll probably become obvious how to build and navigate the structure. If not then at least you should be able to describe /specifically/ what your problem is. -- chris |
|
|
#17 |
|
|
michael wrote:
> I need to write a program that mimics directory structure on PC or UNIX. > after loading the directory structure into such an object , I should be able to > print a particulr node : You can look at the generic directory code at http://geosoft.no/software/index.html#directory You can traverse the file system (see File and File.listFiles) and build Folder and DirectoryItem nodes as you go. To each element in the tree you can ***ocaite a back-end object which in your case will be the capasity-extension or whatever. But beware: Instantiation of sub-structures should be done lazily as an initial scan of a complete file system typically takes a considerable amount of time. |