简体   繁体   中英

Get all file with Directory.GetFiles(), this get a file but not exist in my folder

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);

~$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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM