DeleteDirectory() public method

public DeleteDirectory ( string dir ) : void
dir string
return void
Exemplo n.º 1
0
 public void DeleteDirectory_ThrowsArgumentNull()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         Assert.Throws <ArgumentNullException>(() => isf.DeleteDirectory(null));
     }
 }
Exemplo n.º 2
0
 public void DeleteDirectory_RaisesInvalidPath()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         Assert.Throws <IsolatedStorageException>(() => isf.DeleteDirectory("\0bad"));
     }
 }
Exemplo n.º 3
0
 public void DeleteDirectory_ThrowsIsolatedStorageException()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         isf.Remove();
         Assert.Throws <IsolatedStorageException>(() => isf.DeleteDirectory("foo"));
     }
 }
Exemplo n.º 4
0
 public void DeleteDirectory_ThrowsInvalidOperationException()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         isf.Close();
         Assert.Throws <InvalidOperationException>(() => isf.DeleteDirectory("foo"));
     }
 }
Exemplo n.º 5
0
        public void DeleteDirectory_DeleteNested()
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                string directory    = "DeleteDirectory_DeleteNested";
                string subdirectory = Path.Combine(directory, "Subdirectory");
                isf.CreateDirectory(subdirectory);
                Assert.True(isf.DirectoryExists(subdirectory));

                // Shouldn't be recursive
                Assert.Throws <IsolatedStorageException>(() => isf.DeleteDirectory(directory));

                isf.DeleteDirectory(subdirectory);
                isf.DeleteDirectory(directory);
                Assert.False(isf.DirectoryExists(directory));
            }
        }
        /// <summary>
        /// Deletes all of the folders and their contents in a given file-path.
        /// </summary>
        /// <param name="filepath">A valid filepath in IsolatedStorage.</param>
        /// <param name="storage">A reference to a valid IsolateStorageFile object.</param>
        public static void DeleteDirectoryTree(string filepath, IsolatedStorageFile storage)
        {
            //Bail if we don't detect any folders
            if (!HasDirectories(filepath)) return;

            //Get the root folder from the path
            var folderPath = GetRootDirectory(filepath);

            //Delete the root directory and have it cascade down
            storage.DeleteDirectory(folderPath);
        }
        public void DirectoryExists_Existance()
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                isf.CreateDirectory("DirectoryExists_Existance");

                Assert.True(isf.DirectoryExists("DirectoryExists_Existance"));
                isf.DeleteDirectory("DirectoryExists_Existance");
                Assert.False(isf.DirectoryExists("DirectoryExists_Existance"));
            }
        }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
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);
     }
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
		// use the caller stack to execute some write operations
		private void Write (IsolatedStorageFile isf)
		{
			isf.CreateDirectory ("testdir");

			string filename = Path.Combine ("testdir", "file");
			using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (filename, FileMode.Create, isf)) {
			}
			isf.DeleteFile (filename);

			isf.DeleteDirectory ("testdir");
			try {
				isf.Remove ();
			}
			catch (IsolatedStorageException) {
				// fx 1.x doesn't like removing when things "could" still be in use
			}
		}
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
 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);
 }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
 public void MoveOldCrashlogsIfNeeded(IsolatedStorageFile store)
 {
     try
     {
         if (store.DirectoryExists(Constants.OldCrashDirectoryName))
         {
             var files = store.GetFileNames(Path.Combine(Constants.OldCrashDirectoryName, Constants.CrashFilePrefix + "*.log"));
             if (files.Length > 0)
             {
                 if (!store.DirectoryExists(Constants.CrashDirectoryName))
                 {
                     store.CreateDirectory(Constants.CrashDirectoryName);
                 }
                 foreach (var fileName in files)
                 {
                     store.MoveFile(Path.Combine(Constants.OldCrashDirectoryName, Path.GetFileName(fileName)), Path.Combine(Constants.CrashDirectoryName, Path.GetFileName(fileName)));
                 }
                 if (store.GetFileNames(Path.Combine(Constants.OldCrashDirectoryName, Constants.CrashFilePrefix + "*.*")).Length == 0)
                 {
                     store.DeleteDirectory(Constants.OldCrashDirectoryName);
                 }
             }
         }
     }
     catch (Exception e)
     {
         HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e);
     }
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        private static void DeleteAllFiles(IsolatedStorageFile isf)
        {
            if (false == isf.DirectoryExists(Constants.MyScriptsDirectoryName))
                return;

            var filesDel = isf.GetFileNames(string.Format("{0}\\*", Constants.MyScriptsDirectoryName));
            foreach (var f in filesDel)
            {
                isf.DeleteFile(Constants.MyScriptsDirectoryName + "\\" + f);
            }
            isf.DeleteDirectory(Constants.MyScriptsDirectoryName);
        }
Exemplo n.º 19
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);
 }
Exemplo n.º 20
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);
     }
 }
Exemplo n.º 21
0
        private static void DeleteFileHelper(IsolatedStorageFile isoStore, string path)
        {
            int retries = 3;

            while (retries-- > 0)
            {
                try
                {
                    if (isoStore.FileExists(path))
                    {
                        isoStore.DeleteFile(path);

                        try
                        {
                            isoStore.DeleteDirectory(Path.GetDirectoryName(path));
                        }
                        catch (IsolatedStorageException)
                        {
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                catch (IsolatedStorageException)
                {
                    // random iso-store failures..
                    //
                    Thread.Sleep(50);
                }
                return;
            }
        }
Exemplo n.º 22
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);
     }
 }