Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
how I can write C# code to sort all the files in my PC according to thier types and show all of them in treeview
Posted 12-Nov-12 4:03am
Comments
joshrduncan2012 at 12-Nov-12 9:24am
   
What have you tried so far?
ryanb31 at 12-Nov-12 10:05am
   
There are many ways to do this. Basically you'll have to traverse the file system and add to treeview. What have you done and where are you stuck?
Nelek at 12-Nov-12 10:36am
   
Sergey Alexandrovich Kryukov at 12-Nov-12 14:52pm
   
Why?!
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you look at Directory.GetFiles, you will find it has an overload which returns all files in subdirectories as well as the specified folder.
            string[] files = Directory.GetFiles(path, ".", SearchOption.AllDirectories);
It would then be pretty simple to sort them using Linq methods:
            var sorted = files.OrderBy(s => new FileInfo(s).Extension);
Then all you have to do is display them in whatever way your feel like!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 455
1 Sergey Alexandrovich Kryukov 445
2 Maciej Los 290
3 ProgramFOX 275
4 CHill60 225
0 OriginalGriff 550
1 Sergey Alexandrovich Kryukov 470
2 Maciej Los 310
3 ProgramFOX 275
4 Peter Leow 250


Advertise | Privacy | Mobile
Web02 | 2.8.150331.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100