Пример #1
0
 public string ChangeDir(string path)
 {
     //  Take data from a path
     //  if problem occured, fill values empty
     if (path == null || path == "" || !Directory.Exists(path))
     {
         loaded      = false;
         cangoback   = false;
         currentpath = "";
         subfiles    = new string[0];
         subdirs     = new string[0];
         stringlist  = null;
     }
     else
     {
         try {
             cangoback   = Directory.GetParent(path) != null;
             currentpath = FileBrowser.ChangeDirectory(path);
             subfiles    = FileBrowser.GetFiles(path);
             subdirs     = FileBrowser.GetDirectories(path);
             stringlist  = BuildStringArray();
             loaded      = true;
         } catch (Exception) {
             ChangeDir(null);
         }
     }
     return(currentpath);
 }
        public void GetDirectories_InvalidPath_ReturnEmptyArray()
        {
            FileBrowser testBrowser = new FileBrowser();

            DirectoryInfo[] resultArray = testBrowser.GetDirectories();

            int expected = 0;
            int result   = resultArray.Length;

            Assert.AreEqual(expected, result);
        }
        public void GetDirectories_EmptyStringPath_ReturnEmptyArray()
        {
            string drivePath = "";

            FileBrowser testBrowser = new FileBrowser();

            testBrowser.SetDrivePath(drivePath);
            DirectoryInfo[] resultArray = testBrowser.GetDirectories();

            int expected = 0;
            int result   = resultArray.Length;

            Assert.AreEqual(expected, result);
        }
        public void GetDirectories_ValidPath_ReturnArrayWithMoreElements()
        {
            string drivePath = "C:\\";

            FileBrowser testBrowser = new FileBrowser();

            testBrowser.SetDrivePath(drivePath);
            DirectoryInfo[] resultArray = testBrowser.GetDirectories();

            DirectoryInfo[] expectedArray = new DirectoryInfo(drivePath).GetDirectories();

            int expected = expectedArray.Length;
            int result   = resultArray.Length;

            Assert.AreEqual(expected, result);
        }
Пример #5
0
 public string TryChangeDir(string path)
 {
     //  Take data from a path
     //  if problem occured, keep the previous state
     if (path != null && path != "" || !Directory.Exists(path))
     {
         try
         {
             bool     tryCGB = Directory.GetParent(path) != null;
             string   tryCP  = FileBrowser.ChangeDirectory(path);
             string[] trySF  = FileBrowser.GetFiles(path);
             string[] trySD  = FileBrowser.GetDirectories(path);
             //If a problem accured, the values won't be assigned
             cangoback   = tryCGB;
             currentpath = tryCP;
             subdirs     = trySD;
             subfiles    = trySF;
             loaded      = true;
             stringlist  = BuildStringArray();
         } catch (Exception) {}
     }
     return(currentpath);
 }