本文整理汇总了C#中System.IO.IsolatedStorage.IsolatedStorageFile.GetDirectoryNames方法的典型用法代码示例。如果您正苦于以下问题:C# IsolatedStorageFile.GetDirectoryNames方法的具体用法?C# IsolatedStorageFile.GetDirectoryNames怎么用?C# IsolatedStorageFile.GetDirectoryNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.IsolatedStorage.IsolatedStorageFile
的用法示例。
在下文中一共展示了IsolatedStorageFile.GetDirectoryNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIsolatedStorageView
//*******************************************************************************************
//Enable this if you'd like to be able access the list from outside the class. All list
//methods are commented out below and replaced with Debug.WriteLine.
//Default implementation is to simply output the directories to the console (Debug.WriteLine)
//so if it looks like nothing's happening, check the Output window :) - keyboardP
// public static List<string> listDir = new List<string>();
//********************************************************************************************
//Use "*" as the pattern string in order to retrieve all files and directories
public static void GetIsolatedStorageView(string pattern, IsolatedStorageFile storeFile)
{
string root = System.IO.Path.GetDirectoryName(pattern);
if (root != "")
{
root += "/";
}
string[] directories = storeFile.GetDirectoryNames(pattern);
//if the root directory has not FOLDERS, then the GetFiles() method won't be called.
//the line below calls the GetFiles() method in this event so files are displayed
//even if there are no folders
//if (directories.Length == 0)
GetFiles(root, "*", storeFile);
for (int i = 0; i < directories.Length; i++)
{
string dir = directories[i] + "/";
//Add this directory into the list
// listDir.Add(root + directories[i]);
//Write to output window
Debug.WriteLine(root + directories[i]);
//Get all the files from this directory
GetFiles(root + directories[i], pattern, storeFile);
//Continue to get the next directory
GetIsolatedStorageView(root + dir + "*", storeFile);
}
}
示例2: GetAllDirectories
// Method to retrieve all directories, recursively, within a store.
public static List<String> GetAllDirectories(string pattern, IsolatedStorageFile storeFile)
{
// Get the root of the search string.
string root = Path.GetDirectoryName(pattern);
if (root != "")
{
root += "/";
}
// Retrieve directories.
List<String> directoryList = new List<String>(storeFile.GetDirectoryNames(pattern));
// Retrieve subdirectories of matches.
for (int i = 0, max = directoryList.Count; i < max; i++)
{
string directory = directoryList[i] + "/";
List<String> more = GetAllDirectories(root + directory + "*", storeFile);
// For each subdirectory found, add in the base path.
for (int j = 0; j < more.Count; j++)
{
more[j] = directory + more[j];
}
// Insert the subdirectories into the list and
// update the counter and upper bound.
directoryList.InsertRange(i + 1, more);
i += more.Count;
max += more.Count;
}
return directoryList;
}
示例3: CollectSubdirectoriesAndFilesBreadthFirst
/// <summary>
/// Collects the Paths of Directories and Files inside a given Directory relative to it.
/// </summary>
/// <param name="Iso">The Isolated Storage to Use</param>
/// <param name="directory">The Directory to crawl</param>
/// <param name="relativeSubDirectories">relative Paths to the subdirectories in the given directory, ordered top - down</param>
/// <param name="relativeSubFiles">relative Paths to the files in the given directory and its children, ordered top - down</param>
private static void CollectSubdirectoriesAndFilesBreadthFirst(IsolatedStorageFile Iso, string directory, out IList<string> relativeSubDirectories, out IList<string> relativeSubFiles)
{
var relativeDirs = new List<string>();
var relativeFiles = new List<string>();
var toDo = new Queue<string>();
toDo.Enqueue(string.Empty);
while (toDo.Count > 0)
{
var relativeSubDir = toDo.Dequeue();
var absoluteSubDir = Path.Combine(directory, relativeSubDir);
var queryString = string.Format("{0}\\*", absoluteSubDir);
foreach (var file in Iso.GetFileNames(queryString))
{
relativeFiles.Add(Path.Combine(relativeSubDir, file));
}
foreach (var dir in Iso.GetDirectoryNames(queryString))
{
var relativeSubSubdir = Path.Combine(relativeSubDir, dir);
toDo.Enqueue(relativeSubSubdir);
relativeDirs.Add(relativeSubSubdir);
}
}
relativeSubDirectories = relativeDirs;
relativeSubFiles = relativeFiles;
}
示例4: InnerClear
private void InnerClear(IsolatedStorageFile iso, string path) {
var fs = iso.GetFileNames(string.Format("{0}/*", path));
foreach (var f in fs) {
iso.DeleteFile(Path.Combine(path, f));
}
var ds = iso.GetDirectoryNames(string.Format("{0}/*", path));
foreach (var d in ds) {
var sp = Path.Combine(path, d);
this.InnerClear(iso, sp);
iso.DeleteDirectory(sp);
}
}
示例5: Read
// use the caller stack to execute some read operations
private void Read (IsolatedStorageFile isf)
{
Assert.IsNotNull (isf.GetDirectoryNames ("*"), "GetDirectoryNames");
Assert.IsNotNull (isf.GetFileNames ("*"), "GetFileNames");
try {
Assert.IsTrue (isf.CurrentSize >= 0, "CurrentSize");
Assert.IsTrue (isf.MaximumSize >= isf.CurrentSize, "MaximumSize");
}
catch (InvalidOperationException) {
// roaming
}
}
示例6: DeleteDirectory
/// <summary>
/// �ڴ洢����ɾ��Ŀ¼
/// </summary>
/// <param name="storage"></param>
/// <param name="dirName"></param>
public static void DeleteDirectory(IsolatedStorageFile storage, string dirName)
{
try
{
if (!string.IsNullOrEmpty(dirName) && storage.GetDirectoryNames(dirName).Length > 0)
{
storage.DeleteDirectory(dirName);
}
}
catch (Exception ex)
{
throw new Exception("���ڴ洢����ɾ��Ŀ¼.", ex);
}
}
示例7: RecursiveDeleteDirectory
public static void RecursiveDeleteDirectory(string directory, IsolatedStorageFile store)
{
foreach (var fileName in store.GetFileNames(directory + "\\*"))
{
store.DeleteFile(directory + "\\" + fileName);
}
foreach (var directoryName in store.GetDirectoryNames(directory + "\\*"))
{
RecursiveDeleteDirectory(directory + "\\" + directoryName, store);
}
store.DeleteDirectory(directory);
}
示例8: IsolatedStorageCacheItem
/// <summary>
/// Instance constructor. Ensures that the storage location in Isolated Storage is prepared
/// for reading and writing. This class stores each individual field of the CacheItem into its own
/// file inside the directory specified by itemDirectoryRoot.
/// </summary>
/// <param name="storage">Isolated Storage area to use. May not be null.</param>
/// <param name="itemDirectoryRoot">Complete path in Isolated Storage where the cache item should be stored. May not be null.</param>
/// <param name="encryptionProvider">Encryption provider</param>
public IsolatedStorageCacheItem(IsolatedStorageFile storage, string itemDirectoryRoot, IStorageEncryptionProvider encryptionProvider)
{
if (storage.GetDirectoryNames(itemDirectoryRoot).Length == 0)
{
// avoid creating if already exists - work around for partial trust
storage.CreateDirectory(itemDirectoryRoot);
}
keyField = new IsolatedStorageCacheItemField(storage, "Key", itemDirectoryRoot, encryptionProvider);
valueField = new IsolatedStorageCacheItemField(storage, "Val", itemDirectoryRoot, encryptionProvider);
scavengingPriorityField = new IsolatedStorageCacheItemField(storage, "ScPr", itemDirectoryRoot, encryptionProvider);
refreshActionField = new IsolatedStorageCacheItemField(storage, "RA", itemDirectoryRoot, encryptionProvider);
expirationsField = new IsolatedStorageCacheItemField(storage, "Exp", itemDirectoryRoot, encryptionProvider);
lastAccessedField = new IsolatedStorageCacheItemField(storage, "LA", itemDirectoryRoot, encryptionProvider);
}
示例9: DeleteDirectoryRecursive
public void DeleteDirectoryRecursive(IsolatedStorageFile isolatedStorageFile, String dirName)
{
String pattern = dirName + @"\*";
String[] files = isolatedStorageFile.GetFileNames(pattern);
foreach (String fName in files)
{
isolatedStorageFile.DeleteFile(Path.Combine(dirName, fName));
}
String[] dirs = isolatedStorageFile.GetDirectoryNames(pattern);
foreach (String dName in dirs)
{
DeleteDirectoryRecursive(isolatedStorageFile, Path.Combine(dirName, dName));
}
isolatedStorageFile.DeleteDirectory(dirName);
}
示例10: DeleteDirectoryRecursively
public static void DeleteDirectoryRecursively(IsolatedStorageFile storageFile, string directoryName)
{
var pattern = directoryName + @"\*";
var files = storageFile.GetFileNames(pattern);
foreach (var fileName in files)
{
storageFile.DeleteFile(Path.Combine(directoryName, fileName));
}
var dirs = storageFile.GetDirectoryNames(pattern);
foreach (var dirName in dirs)
{
DeleteDirectoryRecursively(storageFile, Path.Combine(directoryName, dirName));
}
storageFile.DeleteDirectory(directoryName);
}
示例11: DeleteDirectory
public static void DeleteDirectory(IsolatedStorageFile store, String root)
{
String dir = root;
// delete file in current dir
foreach (String file in store.GetFileNames(dir + "/*"))
{
store.DeleteFile(dir + "/" + file);
}
// delete sub-dir
foreach (String subdir in store.GetDirectoryNames(dir + "/*"))
{
DeleteDirectory(store, dir + "/" + subdir + "/");
}
// delete current dir
store.DeleteDirectory(dir);
}
示例12: CopyDirectory
public void CopyDirectory(string sourcePath, string destinationPath, IsolatedStorageFile iso)
{
if (!iso.DirectoryExists(sourcePath))
return;
var folders = iso.GetDirectoryNames(sourcePath + "/" + "*.*");
foreach (var folder in folders)
{
string sourceFolderPath = sourcePath + "/" + folder;
string destinationFolderPath = destinationPath + "/" + folder;
iso.CreateDirectory(destinationFolderPath);
CopyDirectory(sourceFolderPath, destinationFolderPath, iso);
}
foreach (var file in iso.GetFileNames(sourcePath + "/" + "*.*"))
{
string sourceFilePath = sourcePath + "/" + file;
string destinationFilePath = destinationPath + "/" + file;
iso.CopyFile(sourceFilePath, destinationFilePath);
}
}
示例13: Initialize
private void Initialize()
{
#if WINDOWS_PHONE
store = IsolatedStorageFile.GetUserStoreForApplication();
#else
// Application-scoped IS requires ClickOnce security, which we don't
//want to depend on in the regular Windows environment
// WP7 apps are always deployed with manifests, though, so it is not an issue
// http://blogs.msdn.com/b/shawnhar/archive/2010/12/16/isolated-storage-windows-and-clickonce.aspx
store = IsolatedStorageFile.GetUserStoreForDomain();
#endif
if (store.GetDirectoryNames(storageAreaName).Length == 0)
{
// avoid creating if already exists - work around for partial trust
store.CreateDirectory(storageAreaName);
}
serializer = new XmlSerializer(typeof(List<ItemModel>), new Type[] { typeof(ItemModel) });
}
示例14: getFiles
private Collection<SearchableFile> getFiles(string pattern, IsolatedStorageFile storeFile, Collection<SearchableFile> list)
{
string root = System.IO.Path.GetDirectoryName(pattern);
foreach (string fileName in storeFile.GetFileNames(pattern))
{
string filePath = System.IO.Path.Combine(root, fileName);
string fileText = string.Empty;
using (StreamReader myReader = new StreamReader(new IsolatedStorageFileStream(filePath, FileMode.Open, storeFile)))
{
fileText = myReader.ReadToEnd();
}
list.Add(new SearchableFile(filePath, fileName, root, storeFile.GetLastWriteTime(filePath), fileText));
}
foreach (string dirName in storeFile.GetDirectoryNames(pattern))
{
pattern = System.IO.Path.Combine(root, dirName);
list = getFiles(pattern + "/*", storeFile, list);
}
return list;
}
示例15: AddFileToDirectory
// 用递归方法增加目录/文件
void AddFileToDirectory(IsoDirectory dir, IsolatedStorageFile isf)
{
string[] childrendir, childrenfile;
if (string.IsNullOrEmpty(dir.FilePath))
{
childrendir = isf.GetDirectoryNames();
childrenfile = isf.GetFileNames();
}
else
{
childrendir = isf.GetDirectoryNames(dir.FilePath + "/");
childrenfile = isf.GetFileNames(dir.FilePath + "/");
}
// 增加目录实体
foreach (var dirname in childrendir)
{
var childdir = new IsoDirectory(dirname, dir.FilePath + "/" + dirname);
AddFileToDirectory(childdir, isf);
dir.Children.Add(childdir);
}
// 增加文件实体
foreach (var filename in childrenfile)
{
dir.Children.Add(new IsoFile(filename, dir.FilePath + "/" + filename));
}
}