Пример #1
0
 public static void DeleteDirectory(string directoryPath)
 {
     if (DirFileHelper.IsExistDirectory(directoryPath))
     {
         Directory.Delete(directoryPath, true);
     }
 }
Пример #2
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);
        }
Пример #3
0
 public static void CreateDirectory(string directoryPath)
 {
     if (!DirFileHelper.IsExistDirectory(directoryPath))
     {
         Directory.CreateDirectory(directoryPath);
     }
 }
Пример #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("\\")));
             }
         }
     }
 }
Пример #5
0
 public static string[] GetFileNames(string directoryPath)
 {
     if (!DirFileHelper.IsExistDirectory(directoryPath))
     {
         throw new FileNotFoundException();
     }
     return(Directory.GetFiles(directoryPath));
 }
Пример #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();
        }
Пример #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);
            }
        }
Пример #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]);
         }
     }
 }
Пример #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;
     }
 }
Пример #10
0
        public static bool Contains(string directoryPath, string searchPattern)
        {
            bool result;

            try
            {
                string[] fileNames = DirFileHelper.GetFileNames(directoryPath, searchPattern, false);
                if (fileNames.Length == 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(result);
        }
Пример #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);
 }
Пример #12
0
 public static void ClearFile(string filePath)
 {
     File.Delete(filePath);
     DirFileHelper.CreateFile(filePath);
 }