Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. What does "GetFiles" do in system directories?

What does "GetFiles" do in system directories?

Scheduled Pinned Locked Moved Visual Basic
questiondata-structureshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sonhospa
    wrote on last edited by
    #1

    Hello, I have a funny question which arises from the effects I recognize in a sample app. At a certain point the sample app reads the files of a directory into an array. Since the path to "System32" was anyway pre-set in the sample, I realized the array gets filled with 2560 strings in the array - despite of more than 5000 files in that directory. After changing the path to another Windows directory ("System"), the array again filled with 2560 files only... No error in both cases. Then I changed the path to a different directory (holding approx. 6000 files), and the "GetFiles" array got filled with exactly the number of files existing. I tried this several times with other directories, and it seems that everything works (i.e. reads and counts) fine as long as the path isn't a system directory. Is this behaviour normal? Or what else might be going on? Thank you for any insights Mick

    Richard DeemingR B S 3 Replies Last reply
    0
    • S Sonhospa

      Hello, I have a funny question which arises from the effects I recognize in a sample app. At a certain point the sample app reads the files of a directory into an array. Since the path to "System32" was anyway pre-set in the sample, I realized the array gets filled with 2560 strings in the array - despite of more than 5000 files in that directory. After changing the path to another Windows directory ("System"), the array again filled with 2560 files only... No error in both cases. Then I changed the path to a different directory (holding approx. 6000 files), and the "GetFiles" array got filled with exactly the number of files existing. I tried this several times with other directories, and it seems that everything works (i.e. reads and counts) fine as long as the path isn't a system directory. Is this behaviour normal? Or what else might be going on? Thank you for any insights Mick

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Sounds like you're running a 32-bit application on a 64-bit OS. The File System Redirector[^] intercepts your request to access C:\Windows\System32, and redirects it to C:\Windows\SysWOW64 instead. You can either compile your application as 64-bit; use the special SysNative alias for the System32 directory; or P/Invoke the Wow64DisableWow64FsRedirection[^] and Wow64RevertWow64FsRedirection[^] functions to disable the file system redirector for your application.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Sounds like you're running a 32-bit application on a 64-bit OS. The File System Redirector[^] intercepts your request to access C:\Windows\System32, and redirects it to C:\Windows\SysWOW64 instead. You can either compile your application as 64-bit; use the special SysNative alias for the System32 directory; or P/Invoke the Wow64DisableWow64FsRedirection[^] and Wow64RevertWow64FsRedirection[^] functions to disable the file system redirector for your application.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        Sonhospa
        wrote on last edited by
        #3

        Thank you, Richard, for sharing the knowledge as well as probable solutions. It's very likely that the 32/64bit thing is the reason for the effect. As I wrote before, it's a sample app I examined, so right now I don't need the solutions. But now I'm more prepared for that kind of possible surprises :rolleyes: There's still some queston marks, since SysWOW64 has only 2517 (not 2560) file entries on top-level, but it's good enough for having a first clue and some attention around that issue. Regards Mick

        1 Reply Last reply
        0
        • S Sonhospa

          Hello, I have a funny question which arises from the effects I recognize in a sample app. At a certain point the sample app reads the files of a directory into an array. Since the path to "System32" was anyway pre-set in the sample, I realized the array gets filled with 2560 strings in the array - despite of more than 5000 files in that directory. After changing the path to another Windows directory ("System"), the array again filled with 2560 files only... No error in both cases. Then I changed the path to a different directory (holding approx. 6000 files), and the "GetFiles" array got filled with exactly the number of files existing. I tried this several times with other directories, and it seems that everything works (i.e. reads and counts) fine as long as the path isn't a system directory. Is this behaviour normal? Or what else might be going on? Thank you for any insights Mick

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Be careful with the overloads:

          string[] files = System.IO.Directory.GetFiles(@"C:\windows\system32", "*.*", SearchOption.AllDirectories);

          looks into sub-directories, while the simple form

          string[] files = System.IO.Directory.GetFiles(@"C:\windows\system32");

          does not. I think that is the reason for the differences you experienced.

          S 1 Reply Last reply
          0
          • B Bernhard Hiller

            Be careful with the overloads:

            string[] files = System.IO.Directory.GetFiles(@"C:\windows\system32", "*.*", SearchOption.AllDirectories);

            looks into sub-directories, while the simple form

            string[] files = System.IO.Directory.GetFiles(@"C:\windows\system32");

            does not. I think that is the reason for the differences you experienced.

            S Offline
            S Offline
            Sonhospa
            wrote on last edited by
            #5

            Thank you, Bernhard - that's indeed a very good point to look at. Unfortunately, right now I can't look up which overload was used in the sample... most probably I deleted it after having the code run for demonstration of its methods. But I'm going to check your hint later today.

            1 Reply Last reply
            0
            • S Sonhospa

              Hello, I have a funny question which arises from the effects I recognize in a sample app. At a certain point the sample app reads the files of a directory into an array. Since the path to "System32" was anyway pre-set in the sample, I realized the array gets filled with 2560 strings in the array - despite of more than 5000 files in that directory. After changing the path to another Windows directory ("System"), the array again filled with 2560 files only... No error in both cases. Then I changed the path to a different directory (holding approx. 6000 files), and the "GetFiles" array got filled with exactly the number of files existing. I tried this several times with other directories, and it seems that everything works (i.e. reads and counts) fine as long as the path isn't a system directory. Is this behaviour normal? Or what else might be going on? Thank you for any insights Mick

              S Offline
              S Offline
              Sonhospa
              wrote on last edited by
              #6

              Now, thanks to the insights of my helpers, I could make it clearer. I only checked the top-level number of files using

              Directory.GetFiles(pfad, "*.*", SearchOption.TopDirectoryOnly))

              Here's what I found: • there's no redirection to "SysWOW64" once "System32" is specified as path. I can get the files of both, once set as path. • the result 2560 was correct, but I could only verify this number after setting the system files (etc) to visible in the folder options! • i.e. the GetFiles method counts hidden files as well (which it is supposed to do) So in the end my question arose out of not considering that, in the Windows directory and it's subdirectories, many files are hidden and/or system files. The GetFiles method was completely ok, only my verification wasn't. Thank you Mick

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups