Are they equivalent or alternatives to each other? Is any of them deprecated and if so which one? Which one is recommended for use in an ASP.NET web application. My aim is to extract all files from a specific directory recursively.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Also an important note if you have to do several actions on directory DirectoryInfo will have performance advantage as it will not require security privileges check on each action.
DirectoryInfo is (basically) the Directory class but is used in a non-static context. If you are going to be making many calls to the FileSystem, especially when its the same folder or in subdirectory of said folder, MSDN suggests using DirectoryInfo.
Directory is a static class that provides static methods for working with directories. DirectoryInfo is an instance of a class that provides information about a specific directory. So for example if you wanted the information about C:\Temp:
If you just wanted the names as strings it might be quicker and easier to avoid creating an instance of DirectoryInfo by using the static methods of Directory.
In short, it really doesn't matter which you use as long as it does what you want. Neither is recommended over the other.
DirectoryInfo has a DirectoryInfo.GetFiles Method that probably meet your requirements.
Directory
Directory Info Class