Ok, so here is my code
private void ChargerRep(TreeNodeCollection nodes, string rep)
{
//contruction de root
TreeNode node = new TreeNode(rep);
nodes.Add(node);
string[] nom = System.IO.Directory.GetDirectories(rep);
string[] fichiers = System.IO.Directory.GetFiles(rep);
//on doit renommer le string repertoire, ou quelquechose qui resemble le string rep
//pour eviter que le programme donne des erreurs. Comme le string fichiers est
//initialisé dans la ligne de code string[] fichiers, ce nouveau variable montrera le
//contenu des fichiers de l'arborescence, qui sont stockés dans le treenode (rep)
foreach (string dir in nom)
{
string d = dir.Substring(dir.LastIndexOf(@"\") + 1);
TreeNode noeud = new TreeNode(d);
node.Nodes.Add(noeud);
}
foreach (string nomFichier in fichiers)
{
if (IsJpegImage(nomFichier))
{
string nomF = nomFichier.Substring(nomFichier.LastIndexOf(@"\") + 1);
TreeNode noeud = new TreeNode(nomF);
node.Nodes.Add(noeud);
}
}
//nodes.Add(node);
}
Sorry if the comments in the code are in french. Ok what I am trying to do is to have the treeview list the chosen folder and the subfolders, with the corresponding jpeg files in each subfolder, if applicable. Problem is that while I can get the subfolders to show, they are just listed all first as a list, then the files are listed afterwards, as a list.
Here is the function using this one:
private void menuItemRepertoire_Click(object sender, EventArgs e)
{
//ouvreRepertoire.Rootfolder = Environment.SpecialFolder.Personal;
if (ouvreRepertoire.ShowDialog() == DialogResult.OK)
{
//nettoie les donnees stockees pour l'utilisation
arbreImages.Nodes.Clear();
ChargerRep(arbreImages.Nodes, ouvreRepertoire.SelectedPath);
//
}
}
I am quite lost trying to get it to list it by subfolder, any suggestions? Oh I tried DirectoryInfo, it only results in massive errors, I gave up trying to use it, although it seems nice, my teacher uses a weird coding technique...