0

I have a problem with Directory.GetFiles(). I get all file with it, but I have a file doesn't not exist in my folder (file like ~$temp.docx), so what's that problem ?

This is my code. Thanks

string[] files = Directory.GetFiles(Server.MapPath(path), "*.*", SearchOption.AllDirectories);
Diogo Rocha
  • 9,759
  • 4
  • 48
  • 52
  • 1
    Note that the `~$temp.docx` file might have its "hidden" and/or "system file" attribute set, hiding it from normal view in the file explorer... –  Jun 08 '19 at 03:06
  • Possible duplicate of [C# - Get a list of files excluding those that are hidden](https://stackoverflow.com/questions/2418270/c-sharp-get-a-list-of-files-excluding-those-that-are-hidden) – Aydin Jun 08 '19 at 08:30

2 Answers2

2

~$temp.docx is a hidden file. If you dont need any of the hidden files in a folder you could just exclude them. Which is discussed in this thread: C# - Get a list of files excluding those that are hidden

0

I'd wager that there IS a file like that in your directory, but you can's see it with File Explorer. That kind of file is a hidden file that is created when you have a word document open in Microsoft Word. Windows File Explorer doesn't show those files by default when you open up a folder and look at the files. You need to go to View -> Options -> Advanced Settings -> Show Hidden Files and set it to show hidden files. Then you'll see that file with File Explorer as well as your C# code.

Nick Garyu
  • 506
  • 2
  • 5