Results 1 to 8 of 8

Thread: [RESOLVED] Get number of files in C:\

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    84

    Resolved [RESOLVED] Get number of files in C:\

    Hi guys, i want to know the total number of files in my C:\ partition, how can i do this?
    Thx all

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Get number of files in C:\

    VB Code:
    1. Dim x as new System.IO.DirectoryInfo("C:\")
    2.              MessageBox.Show(x.GetFiles().Length.ToString())

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    84

    Re: Get number of files in C:\

    Hi, First of all thx for reply but in this method i get only the number of files in C:\ directory, but i want to know all files contained in C:\ partition, the number in the subfolders too, can you help me?

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Get number of files in C:\

    You would have to write a recursive function to do that and just keep returning the sum of the number of files. It should be pretty straightforward. Just use the same method there, but you have to use the GetDirectories function of the drive to get then iterate through each of the sub directories.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    84

    Re: Get number of files in C:\

    It sounds complex :P but i'll try, thx

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Get number of files in C:\

    There's code for a recursive file search in the VB.NET Codebank forum. Note also that you may not have permission to open every folder so you would need to include exception handling for that situation and simply exclude those folders.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    84

    Re: Get number of files in C:\

    Yes, i use a try to log the files impossible to access, i try to search this code, Thx jmcilhinney

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    84

    Re: Get number of files in C:\

    I love you :P i found it and it worked good, Thx a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width