1

Using System.IO.Directory.GetFiles() like this

string[] fileFullPaths1 = Directory.GetFiles(@"C:\Windows\System32", "mycompanyname.scr");
string[] fileFullPaths2 = Directory.GetFiles(@"C:\Windows\SysWOW64", "mycompanyname.scr");

I find the following two files:

  • C:\Windows\System32\mycompanyname.scr
  • C:\Windows\SysWOW64\mycompanyname.scr

Windows explorer cannot see the one in C:\Windows\System32, nor can a command line dir. Furthermore, my own code that searches the MFT shows that there is only one instance of mycompanyname.scr in the MFT and its parent directory record number points to C:\Windows\SysWOW64, so I don't think that hard links are confusing the issue. I have also checked that neither of the two directories are junction points.

Could someone please explain why this is?

Rob B
  • 656
  • 1
  • 5
  • 17
  • Probably http://msdn.microsoft.com/en-us/library/windows/desktop/aa365743(v=vs.85).aspx – ta.speot.is May 15 '14 at 09:47
  • Your application is 32-bit, so its System32 directory is redirected to SysWOW64. Read [MSDN: File System Redirector](http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx). – CodeCaster May 15 '14 at 09:48
  • It's almost certainly to do with the [File System Redirector](http://msdn.microsoft.com/en-gb/library/windows/desktop/aa384187(v=vs.85).aspx) - @ta.speot.is - but I wouldn't link them directly to documentation about *disabling* it because that's usually the wrong thing to do. – Damien_The_Unbeliever May 15 '14 at 09:49
  • To be fair, I didn't say much. But the intent was to get OP to read the documentation. – ta.speot.is May 15 '14 at 09:49
  • You have all been most helpful, and indeed fast! Thanks. WoW64 is not something I know much about, so time for some reading :) – Rob B May 15 '14 at 09:53
  • Sure enough, if I build my little test program as 64-bit, I only see the one in C:\Windows\SysWOW64. – Rob B May 15 '14 at 09:59
  • I think that this answer might be useful for you; http://stackoverflow.com/questions/10600921/directory-getfiles-not-returning-a-file – mmg666 May 15 '14 at 10:00

1 Answers1

0

WOW64 means Windows-on-Windows 64-bit.

SysWOW64 is used to put 32-bit program.
System32 is used to put 64-bit program.

For 32-bit programs, C:\Windows\System32 will always be redirected to C:\Windows\SysWOW64.
For 64-bit programs, C:\Windows\System32 will be redirected to C:\Windows\SysWOW64 if file doesn't exist

You can complie your program to x86 and try again.

AlexB
  • 7,302
  • 12
  • 56
  • 74