GetDirectoryNames() public method

public GetDirectoryNames ( ) : string[]
return string[]
Esempio n. 1
0
        //*******************************************************************************************
        //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);
            }
        }
        // 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;
        }
        /// <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;
        }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
		// 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
			}
		}
Esempio n. 6
0
 /// <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);
     }
 }
Esempio n. 7
0
        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);
        }
        /// <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);
        }
 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);
 }
 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);
 }
        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);
        }
Esempio n. 12
0
        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);
              }
        }
Esempio n. 13
0
        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) });
        }
Esempio n. 14
0
        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;
        }
Esempio n. 15
0
        // 用递归方法增加目录/文件
        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));
            }
        }
Esempio n. 16
0
        private static void CopyDirectory(string sourceDir, string destDir, IsolatedStorageFile isoFile)
        {
            string path;
            if (sourceDir.EndsWith("\\"))
            {
                path = sourceDir;
            }
            else
            {
                path = sourceDir + "\\";
            }

            bool bExists = isoFile.DirectoryExists(destDir);
            if (!bExists)
            {
                isoFile.CreateDirectory(destDir);
            }
            if (!destDir.EndsWith("\\"))
            {
                destDir += "\\";
            }

            string[] files = isoFile.GetFileNames(path + "*");

            if (files.Length > 0)
            {
                foreach (string file in files)
                {
                    isoFile.CopyFile(path + file, destDir + file, true);
                }
            }
            string[] dirs = isoFile.GetDirectoryNames(path + "*");
            if (dirs.Length > 0)
            {
                foreach (string dir in dirs)
                {
                    CopyDirectory(path + dir, destDir + dir, isoFile);
                }
            }
        }
        private void ScanDir(IsolatedStorageFile store, string directory, bool recurse)
        {
            
            try
            {
                string fileSearchPath = Path.Combine(directory, "*.*");
                string[] names = store.GetFileNames(fileSearchPath);

                bool hasMatch = false;
                for (int fileIndex = 0; fileIndex < names.Length; ++fileIndex)
                {
                    if (!fileFilter_.IsMatch(names[fileIndex]))
                    {
                        names[fileIndex] = null;
                    }
                    else
                    {
                        hasMatch = true;
                    }
                }

                OnProcessDirectory(directory, hasMatch);

                if (alive_ && hasMatch)
                {
                    foreach (string fileName in names)
                    {
                        var filePath = Path.Combine(directory, fileName);
                        try
                        {  
                            OnProcessFile(filePath);
                            if (!alive_)
                            {
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            if (!OnFileFailure(filePath, e))
                            {
                                throw;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (!OnDirectoryFailure(directory, e))
                {
                    throw;
                }
            }

            if (alive_ && recurse)
            {
                try
                {
                    string[] names = store.GetDirectoryNames(Path.Combine(directory, "*"));

                    foreach (string subdir in names)
                    {
                        var fulldir = Path.Combine(directory, subdir);
                        if ((directoryFilter_ == null) || (directoryFilter_.IsMatch(fulldir)))
                        {
                            ScanDir(store, fulldir, true);
                            if (!alive_)
                            {
                                break;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (!OnDirectoryFailure(directory, e))
                    {
                        throw;
                    }
                }
            }
        }
Esempio n. 18
0
 // helper function from: http://stackoverflow.com/questions/18422331/easy-way-to-recursively-delete-directories-in-isolatedstorage-on-wp7-8
 private void DeleteDirectoryRecursively(IsolatedStorageFile storageFile, String dirName)
 {
     try
     {
         String pattern = dirName + @"\*";
         String[] files = storageFile.GetFileNames(pattern);
         foreach (var fName in files)
         {
             storageFile.DeleteFile(Path.Combine(dirName, fName));
         }
         String[] dirs = storageFile.GetDirectoryNames(pattern);
         foreach (var dName in dirs)
         {
             DeleteDirectoryRecursively(storageFile, Path.Combine(dirName, dName));
         }
         if (storageFile.DirectoryExists(dirName))
         {
             storageFile.DeleteDirectory(dirName);
         }
     }
     catch(Exception e)
     {
         Debug.WriteLine("Unable to delete directory : " + dirName);
     }
 }
		private void Initialize()
		{
			store = IsolatedStorageFile.GetUserStoreForDomain();
			if (store.GetDirectoryNames(storageAreaName).Length == 0)
			{
				// avoid creating if already exists - work around for partial trust
				store.CreateDirectory(storageAreaName);
			}
		}
Esempio n. 20
0
        private long ComputeDirectorySizes(IsolatedStorageFile iso, string prefix, string[] dirs)
        {
            long fileSize = 0;

            foreach (string dir in dirs)
            {
                string pattern = System.IO.Path.Combine(prefix, System.IO.Path.Combine(dir, "*"));
                fileSize += ComputeFileSize(iso, pattern, iso.GetFileNames(pattern));
                fileSize += ComputeDirectorySizes(iso, dir, iso.GetDirectoryNames(pattern));
            }
            return fileSize;
        }
Esempio n. 21
0
 private void deleteDirectory(IsolatedStorageFile myIsolatedStorage, string directoryMain)
 {
     foreach (string file in myIsolatedStorage.GetFileNames("./" + directoryMain + "/"))
     {
         bool a = myIsolatedStorage.FileExists(directoryMain + "/" + file);
         myIsolatedStorage.DeleteFile(directoryMain + "/" + file);
     }
     foreach (string directory in myIsolatedStorage.GetDirectoryNames("./" + directoryMain + "/"))
     {
         deleteDirectory(myIsolatedStorage,directoryMain+"/"+directory);
         myIsolatedStorage.DeleteDirectory(directoryMain + "/" + directory);
     }
 }
Esempio n. 22
0
        private void DeleteDirectory(string path, IsolatedStorageFile iso)
        {
            if (!iso.DirectoryExists(path))
            return;

              var folders = iso.GetDirectoryNames(path + "/" + "*.*");

              foreach (var folder in folders)
              {
            string folderPath = path + "/" + folder;
            DeleteDirectory(folderPath, iso);
              }

              foreach (var file in iso.GetFileNames(path + "/" + "*.*"))
              {
            iso.DeleteFile(path + "/" + file);
              }

              if (path != "")
            iso.DeleteDirectory(path);
        }
Esempio n. 23
0
 // Can't delete unless empty. Must recursively delete files and folders
 private static void DeleteDirectory(IsolatedStorageFile storage, string dir)
 {
     foreach (var file in storage.GetFileNames(Path.Combine(dir, "*")))
     {
         storage.DeleteFile(Path.Combine(dir, file));
     }
     foreach (var subDir in storage.GetDirectoryNames(Path.Combine(dir, "*")))
     {
         DeleteDirectory(storage, Path.Combine(dir, subDir));
     }
     storage.DeleteDirectory(dir);
 }
Esempio n. 24
0
        private void CopyDirectory(string sourceDir, string destDir, IsolatedStorageFile isoFile)
        {
            string path = File.AddSlashToDirectory(sourceDir);

            bool bExists = isoFile.DirectoryExists(destDir);

            if (!bExists)
            {
                isoFile.CreateDirectory(destDir);
            }

            destDir = File.AddSlashToDirectory(destDir);

            string[] files = isoFile.GetFileNames(path + "*");

            if (files.Length > 0)
            {
                foreach (string file in files)
                {
                    isoFile.CopyFile(path + file, destDir + file, true);
                }
            }
            string[] dirs = isoFile.GetDirectoryNames(path + "*");
            if (dirs.Length > 0)
            {
                foreach (string dir in dirs)
                {
                    CopyDirectory(path + dir, destDir + dir, isoFile);
                }
            }
        }
Esempio n. 25
0
        private static void DeleteRecursive(Path dir, IsolatedStorageFile isf)
        {
            // Delete every subdirectory's contents recursively
            foreach (string subDir in isf.GetDirectoryNames(dir.PathString + "/*"))
                DeleteRecursive(dir.NavigateIn(subDir), isf);
            // Delete every file inside
            foreach (string file in isf.GetFileNames(dir.PathString + "/*"))
                isf.DeleteFile(System.IO.Path.Combine(dir.PathString, file));

            isf.DeleteDirectory(dir.PathString);
        }