1 vote
Directory Tree Order

Description

 
I love this program. Uploading all of my pictures and creating lots of sets would have been a real pain. Thanks so much for creating this program.

One of the only improvements that I can think of is to have the directories sorted (preferrably alphabettically). I do Visual Basic and C, but not much java. However after a quick browse through the source code, I think that adding an array sort between the GetDirectories and foreach function call in the FillTree function of TreeFolders.cs would work.

There is a description of this method at http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.languages.csharp/2007-01/msg03944.html.

Thanks again for this great program

File Attachments


No files are attached


Comments

most recent at top (show oldest at top)
geada wrote Feb 18 2008 at 10:56 PM
This should be easy to include. I will try to put in on the next version.

PaulRounsavall wrote Feb 16 2008 at 4:28 AM
As I said above, I am not a java programmer, but I did a websearch. Try adding the below class in the TreeFolder.cs file.

class NameComparator implements Comparator{
public int compare(Object dir1, Object dir2){

//parameter are of type Object, so we have to downcast it to Employee objects

String dir1Name = ( (DirectoryInfo) dir1 ).getName();
String dir2Name = ( (DirectoryInfo) dir2 ).getName();

//uses compareTo method of String class to compare names of the employee

return dir1Name.compareTo(dir2Name);
}
}

Then add the Arrays.Sort line as shown below.

private void FillTree(TreeNode node, string path, int level, int maxlevel)
{
if (!Directory.Exists(path))
return;

DirectoryInfo dirorg = new DirectoryInfo(path);
DirectoryInfo[] dirs = dirorg.GetDirectories();

Arrays.Sort(dirs, new NameComparator());

foreach (DirectoryInfo di in dirs)
{
// do not show Hidden System folders or Reparse Points (Junctions)
if (((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) &&
((di.Attributes & FileAttributes.System) == FileAttributes.System) ||
((di.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint))
continue;

TreeNode subnode = AddNode(node.Nodes, di.FullName, di.Name);

if (maxlevel != 0 && level < maxlevel)
FillTree(subnode, di.FullName, ++level, maxlevel);
}
}

Updating...
© 2006-2009 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2009.10.27.15987