Click here to Skip to main content
15,445,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,

Part of my code always work fine under Windows 7, now with Windows 10 not works...
The code count Files and Folders inside a External Hard Drive, the same device is used for testing...

Public NDirs, NFiles As Integer



  Try

   NDirs = My.Computer.FileSystem.GetDirectories(My.Settings.BackupDrive, "*", 
   SearchOption.AllDirectories).Count
            
   NFiles = My.Computer.FileSystem.GetFiles(My.Settings.BackupDrive, "*.*", 
   SearchOption.AllDirectories).Count


  Catch ex As Exception


  Finally
    MsgBox("Total Files: " & NFiles.ToString & " / Folders: " & NDirs.ToString)

  End Try

I am not sure is something about the .Net Frameworks (4.0 on Proyect) or something else, just try many options and dont works...

On Win7 get the correct files folder numbers, on Win10 just 0/0.

I read some post in the site, where said about GetDirectories /Files not is a good option and very slow, so can give me some orientation for better way?

Thank you in advance.

What I have tried:

Also I try with Directory.GetDirectories and used convinations at the end like .Count, .LongCount, .Lenght and dont works under Windows 10
Posted
Updated 9-Jun-18 8:09am
v2
Comments
Richard Deeming 9-Jun-18 14:16pm     CRLF
Your code is probably throwing an exception, which you are ignoring. Add code to the Catch block to display the details of the exception.
kmoorevs 16-Jun-18 12:41pm    
You were given two solutions last week. Did anything work for you? After a couple of valid answers here without a positive response, I'll think twice before putting any effort here again.

Windows 10 is stricter than Windows 7; you will need to run your application as administrator to access an external drive.
 
Share this answer
 
Try using the DirectoryInfo class to set your search directory first, then call the methods on it like this:

VB
Dim startDir As New DirectoryInfo(My.Settings.BackupDrive)

If startDir.Exists Then
      NDirs = startDir.GetDirectories("*", SearchOption.AllDirectories).Count
      NFiles = startDir.GetFiles("*", SearchOption.AllDirectories).Count
End If
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900