示例#1
0
        //static void main()
        //{
        //   try
        //   {
        //      //FileAttributes fa = File.GetAttributes(@"C:\users");
        //      //bool flag = (fa & FileAttributes.NotContentIndexed) != 0;
        //      string rootDirectory = Directory.GetDirectoryRoot(Environment.SystemDirectory);
        //      fileRec(rootDirectory);
        //   }
        //   catch (Exception Ex)
        //   {
        //      Console.WriteLine(Ex.Message);
        //   }
        //   Console.Read();
        //}
        static void fileRec(string directoryPath)
        {
            try
             {
            var folders = Directory.GetDirectories(directoryPath);
            if (folders.Length > 0)
            {
               foreach (var folder in folders)
               {
                  try
                  {
                     bool flag;
                     #region method1
                     FileDirectory fd = new FileDirectory(folder);
                     flag = fd.HasWritePermission();
                     #endregion

                     #region method2
                     //FileAttributes fa = File.GetAttributes(folder);
                     //flag = (fa & FileAttributes.NotContentIndexed) != 0;
                     #endregion
                     if (flag)
                     {
                        Console.WriteLine(folder);
                     }
                     else
                     {
                        fileRec(folder);
                     }
                  }
                  catch (Exception Ex)
                  {
                     Console.WriteLine(Ex.Message);
                  }
               }
            }
             }
             catch (Exception Ex)
             {
            Console.WriteLine(Ex.Message);
             }
        }
 public void HasWritePermissionToUnknownDirectory()
 {
     string directoryPath = @"C:\unknown";
      fileDirectory = new FileDirectory(directoryPath);
      fileDirectory.HasWritePermission();
 }
 public void HasWritePermissionToSpecifiedFolder()
 {
     string directoryPath = @"C:\sowndarrajan";
      fileDirectory = new FileDirectory(directoryPath);
      Assert.IsTrue(fileDirectory.HasWritePermission());
 }
 public void HasWritePermissionToFilePath()
 {
     string directoryPath = @"C:\text.txt";
      fileDirectory = new FileDirectory(directoryPath);
      fileDirectory.HasWritePermission();
 }
 public void HasWritePermissionToDesktop()
 {
     string directoryPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);
      fileDirectory = new FileDirectory(directoryPath);
      Assert.IsTrue(fileDirectory.HasWritePermission());
 }
 public void HasWritePermissionSpecialFolderRead()
 {
     string directoryPath = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86);
      fileDirectory = new FileDirectory(directoryPath);
      Assert.IsFalse(fileDirectory.HasWritePermission());
 }
 public void HasWritePermissionEmptyDirectoryPath()
 {
     string directoryPath = string.Empty;
      fileDirectory = new FileDirectory(directoryPath);
      fileDirectory.HasWritePermission();
 }
 public void HasWritePermission()
 {
     string directoryPath = "C:";
      fileDirectory = new FileDirectory(directoryPath);
      Assert.IsFalse(fileDirectory.HasWritePermission());
 }
示例#9
0
        static void Main(string[] args)
        {
            try
             {
            do
            {
               Console.Clear();
               Console.WriteLine("Git training - KalaiSelvan");
               Console.Write("enter directory path : ");
               string directoryPath = Console.ReadLine();
               FileDirectory fd = new FileDirectory(directoryPath);
               bool flag = fd.HasWritePermission();
               //Console.WriteLine(directoryPath);
               Console.WriteLine(directoryPath);
               Console.WriteLine(flag ? "has permission to write" : "access denied");
               Console.WriteLine("do you want to continue?(y)");
               Console.WriteLine("added this in develop branch");
               Console.WriteLine("resolved conflict");

            } while (Console.ReadLine().ToLower().ToString() == "y");

             }
             catch (Exception Ex)
             {
            Console.WriteLine(Ex.Message);
             }
             Console.Read();
        }