I need help about a filesorting algorithm 'couse I can't think.... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I need help about a filesorting algorithm 'couse I can't think....

IDKIDK Posts: 1,784Member
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#
[code]
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);
}
}
}
}
[/code]

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

Happy coding wishes
the one and only
[b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
Sign In or Register to comment.