我有一些存储在IsolatedStorage中的文件.文件属于不同类型.我需要获取所有文件的名称.如何从IsolatedStorage中读取文件名.只需要文件名.
使用该GetFileNames方法.如果您只想要IsolatedStorage根目录中所有文件的名称,您可以
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] fileNames = store.GetFileNames();
}
Run Code Online (Sandbox Code Playgroud)
如果您还想要其他目录中的文件名,您可以使用GetDirectoryNames方法获取所有目录名以检索根级别的所有目录的名称.
GetFileNames并且GetDirectoryNames还有重载方法,它们采用搜索模式字符串并返回与模式匹配的所有文件/目录的名称.
因此,为了获取某个目录中的文件名,您可以
string searchPattern = directory + "\\*";
string[] fileNames = store.GetFileNames(searchPattern);
Run Code Online (Sandbox Code Playgroud)
这将为您提供存储在directory目录中的所有文件的名称.
GetDirectoryNames:http://msdn.microsoft.com/en-us/library/cc190673.aspx
GetFileNames:http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.getfilenames%28v=vs.95%29.aspx
| 归档时间: |
|
| 查看次数: |
2161 次 |
| 最近记录: |