Ejemplo n.º 1
0
        public static bool IsEmptyDirectory(string directoryPath)
        {
            bool result;

            try
            {
                string[] fileNames = DirFileHelper.GetFileNames(directoryPath);
                if (fileNames.Length > 0)
                {
                    result = false;
                }
                else
                {
                    string[] directoryNames = DirFileHelper.GetDirectories(directoryPath);
                    if (directoryNames.Length > 0)
                    {
                        result = false;
                    }
                    else
                    {
                        result = true;
                    }
                }
            }
            catch
            {
                result = true;
            }
            return(result);
        }
Ejemplo n.º 2
0
 public static void DeleteDirectory(string directoryPath)
 {
     if (DirFileHelper.IsExistDirectory(directoryPath))
     {
         Directory.Delete(directoryPath, true);
     }
 }
Ejemplo n.º 3
0
 public static void CreateDirectory(string directoryPath)
 {
     if (!DirFileHelper.IsExistDirectory(directoryPath))
     {
         Directory.CreateDirectory(directoryPath);
     }
 }
Ejemplo n.º 4
0
 public static void DeleteFolderFiles(string varFromDirectory, string varToDirectory)
 {
     Directory.CreateDirectory(varToDirectory);
     if (Directory.Exists(varFromDirectory))
     {
         string[] directories = Directory.GetDirectories(varFromDirectory);
         if (directories.Length > 0)
         {
             string[] array = directories;
             for (int i = 0; i < array.Length; i++)
             {
                 string d = array[i];
                 DirFileHelper.DeleteFolderFiles(d, varToDirectory + d.Substring(d.LastIndexOf("\\")));
             }
         }
         string[] files = Directory.GetFiles(varFromDirectory);
         if (files.Length > 0)
         {
             string[] array = files;
             for (int i = 0; i < array.Length; i++)
             {
                 string s = array[i];
                 File.Delete(varToDirectory + s.Substring(s.LastIndexOf("\\")));
             }
         }
     }
 }
Ejemplo n.º 5
0
 public static string[] GetFileNames(string directoryPath)
 {
     if (!DirFileHelper.IsExistDirectory(directoryPath))
     {
         throw new FileNotFoundException();
     }
     return(Directory.GetFiles(directoryPath));
 }
Ejemplo n.º 6
0
        public static void CreateFile(string dir, string pagestr)
        {
            dir = dir.Replace("/", "\\");
            if (dir.IndexOf("\\") > -1)
            {
                DirFileHelper.CreateDir(dir.Substring(0, dir.LastIndexOf("\\")));
            }
            StreamWriter sw = new StreamWriter(HttpContext.Current.Request.PhysicalApplicationPath + "\\" + dir, false, Encoding.GetEncoding("GB2312"));

            sw.Write(pagestr);
            sw.Close();
        }
Ejemplo n.º 7
0
        public static void Move(string sourceFilePath, string descDirectoryPath)
        {
            string sourceFileName = DirFileHelper.GetFileName(sourceFilePath);

            if (DirFileHelper.IsExistDirectory(descDirectoryPath))
            {
                if (DirFileHelper.IsExistFile(descDirectoryPath + "\\" + sourceFileName))
                {
                    DirFileHelper.DeleteFile(descDirectoryPath + "\\" + sourceFileName);
                }
                File.Move(sourceFilePath, descDirectoryPath + "\\" + sourceFileName);
            }
        }
Ejemplo n.º 8
0
 public static void ClearDirectory(string directoryPath)
 {
     if (DirFileHelper.IsExistDirectory(directoryPath))
     {
         string[] fileNames = DirFileHelper.GetFileNames(directoryPath);
         for (int i = 0; i < fileNames.Length; i++)
         {
             DirFileHelper.DeleteFile(fileNames[i]);
         }
         string[] directoryNames = DirFileHelper.GetDirectories(directoryPath);
         for (int i = 0; i < directoryNames.Length; i++)
         {
             DirFileHelper.DeleteDirectory(directoryNames[i]);
         }
     }
 }
Ejemplo n.º 9
0
 public static void CreateFile(string filePath)
 {
     try
     {
         if (!DirFileHelper.IsExistFile(filePath))
         {
             FileInfo   file = new FileInfo(filePath);
             FileStream fs   = file.Create();
             fs.Close();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 10
0
        public static bool Contains(string directoryPath, string searchPattern, bool isSearchChild)
        {
            bool result;

            try
            {
                string[] fileNames = DirFileHelper.GetFileNames(directoryPath, searchPattern, true);
                if (fileNames.Length == 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(result);
        }
Ejemplo n.º 11
0
 public static string[] GetFileNames(string directoryPath, string searchPattern, bool isSearchChild)
 {
     if (!DirFileHelper.IsExistDirectory(directoryPath))
     {
         throw new FileNotFoundException();
     }
     string[] files;
     try
     {
         if (isSearchChild)
         {
             files = Directory.GetFiles(directoryPath, searchPattern, SearchOption.AllDirectories);
         }
         else
         {
             files = Directory.GetFiles(directoryPath, searchPattern, SearchOption.TopDirectoryOnly);
         }
     }
     catch (IOException ex)
     {
         throw ex;
     }
     return(files);
 }
Ejemplo n.º 12
0
 public static void ClearFile(string filePath)
 {
     File.Delete(filePath);
     DirFileHelper.CreateFile(filePath);
 }