How to delete folder and subfolder in device?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 201211
    New Member
    • Jan 2012
    • 12

    How to delete folder and subfolder in device?

    I test this code and debug on device for the purpose of trying to delete folder:
    Code:
    using System;
    using System.IO;
    
    class Test 
    {
    	
        public static void Main() 
        {
            // Specify the directories you want to manipulate.
            string path = @"\MyDir";
            string subPath = @"\MyDir\temp";
    
            try 
            {
                // Determine whether the directory exists.
                if (!Directory.Exists(path)) 
                {
                    // Create the directory.
                    Directory.CreateDirectory(path);
                }
    
    
                if (!Directory.Exists(subPath)) 
                {
                    // Create the directory.
                    Directory.CreateDirectory(subPath);
                }
    
                // This will succeed because subdirectories are being deleted.
                MessageBox.Show("I am about to attempt to delete {0}", path);
                Directory.Delete(path, true);
                MessageBox.Show("The Delete operation was successful.");
    
            } 
            catch (Exception e) 
            {
                MessageBox.Show("The process failed: {0}", e.ToString());
            } 
            finally {}
        }
    }
    but it not delete the folder after debug on device although appear message box delete operation success...
    any idea?
Working...