Okay so I use this to get every file name in the directory.
string[] fileEntries = Directory.GetFiles(@"C:\");
Now when I do this
foreach (string fileName in fileEntries)
{
treeView1.Nodes.Add(fileName);
}
It works but I dont want it to display the directory. It displays this in the treeview.
C:\test.txt
C:\test2.txt
C:\test3.txt
I just want it to display the file name and not the directory.
hmm, I'd use split with "\\" as the delimeter, and then take the last string in the array.
I dont get what you mean
string[] path = fileEntries.Split("\\");
filename = path[path.Length - 1];
well that worked, but then what about when I'm in a completely different directory?
C:\Users\Ronnie\Documents\test.txt
it should work exactly the same
wierd when I just tried it it returned this
C:UsersRonnieDocumentstest.txt
The idea was to use it like this:
foreach (string filePath in fileEntries)
{
string[] path = filePath.Split("\\");
treeView1.Nodes.Add(path[path.Length - 1]);
}
That worked thanks blizz!