如何读取存储在 IndependentStorage 中的文件的名称 [英] How to read names of files stored in IsolatedStorage

查看:17
本文介绍了如何读取存储在 IndependentStorage 中的文件的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文件存储在 IndependentStorage 中.文件有不同的类型.我需要获取所有文件的名称.如何从 IndependentStorage 读取文件名.只需要文件名.

I have some files which are stored in IsolatedStorage. The files are of different types. I need to get names of all the files. How can I read the file names from IsolatedStorage. Only file name is needed.

推荐答案

使用 GetFileNames 方法.如果你只想要IsolatedStorage根目录下所有文件的名字,你可以

Use the GetFileNames method. If you only want the names of all the files in the root of IsolatedStorage, you could

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
    string[] fileNames = store.GetFileNames();
}

如果你也想要其他目录中的文件名,你可以使用GetDirectoryNames方法来获取所有目录名以检索根级所有目录的名称.

If you want the names of the files inside other directories too, you could use GetDirectoryNames method to get all the directory names to retrieve names of all the directories at root level.

GetFileNamesGetDirectoryNames 也有重载方法,它们采用搜索模式字符串并返回与该模式匹配的所有文件/目录的名称.

GetFileNames and GetDirectoryNames also have overloaded methods which take a search pattern string and return the names of all the files/directories that match the pattern.

因此,为了获取某个目录中的文件名,您可以

So, in order to get names of files inside some directory, you could

string searchPattern = directory + "\\*";
string[] fileNames = store.GetFileNames(searchPattern);

这将为您提供存储在 directory 目录中的所有文件的名称.

This will give you the names of all the files stored in the directory directory.

GetDirectoryNames:http://msdn.microsoft.com/en-我们/图书馆/cc190673.aspx

GetFileNames :http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.getfilenames%28v=vs.95%29.aspx

这篇关于如何读取存储在 IndependentStorage 中的文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆