Algorithms

Moderators: None (Apply to moderate this forum)
Number of threads: 402
Number of posts: 786

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I need help about a filesorting algorithm 'couse I can't think.... Posted by IDK on 19 Feb 2006 at 8:15 AM
I'm sick and can't really focus so I have a grait problem with finnishing a project I'm working on. I wanna finnish this project before school start...

I got some files sorted in folders and the input data for the func is an array something like this: 3,1

What the func should do is:
If where at the lowest level and there's lesser than 3 items in there it should move them to a higher folder level.
If where at the second lowest level, and if there is 1 item there it should move it to a higher folder level.

How do implement that?

This is the code I got in C#
        void sortDirectorys()
        {
            string[] l = minItemTextBox.Text.Split(',');
            int[] d = new int[l.Length];
            for (int i = 0; i < l.Length; i++)
            {
                d[i] = int.Parse(l[i]);
            } //convert the data, from "3,1" to 3,1


            string s = formatSmartString(sortTextBox.Text.ToLower() + "d", "");

            DirectoryInfo rDir = new FileInfo(s).Directory;

            int difLayers =
                numOfChars(sortTextBox.Text.ToLower(), '\\') -
                numOfChars(s, '\\');

            sortDirectorys(rDir, difLayers, d);
        }
        void sortDirectorys(DirectoryInfo d, int layer, int[] data)
        {
            DirectoryInfo[] dirs = d.GetDirectories("*", SearchOption.TopDirectoryOnly);
            FileInfo[] files = d.GetFiles("*", SearchOption.TopDirectoryOnly);

            if (layer < data.Length)
            {
                if ((dirs.Length + files.Length) <= data[layer])
                {
                    for (int i = 0; i < dirs.Length; ++i)
                    {
                         DirectoryInfo newDir = new DirectoryInfo(
                            dirs[i].Parent.Parent.FullName + "\\" +
                            dirs[i].Name + " " + dirs[i].Parent.Name);

                        dirs[i].MoveTo(newDir.FullName);

                        sortDirectorys(newDir, layer - 1, data);
                    }
                }
                else
                {
                    for (int i = 0; i < dirs.Length; ++i)
                    {
                        sortDirectorys(dirs[i], layer - 1, data);
                    }
                }
            }
        }


I can't think any further, can anyone borow me their brian?

Happy coding wishes
the one and only
Niklas Ulvinge aka IDK



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.