Exemplo n.º 1
0
 public static void DeleteDirectory(string directoryPath)
 {
     if (DirFileHelper.IsExistDirectory(directoryPath))
     {
         Directory.Delete(directoryPath, true);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 public static void CreateDirectory(string directoryPath)
 {
     if (!DirFileHelper.IsExistDirectory(directoryPath))
     {
         Directory.CreateDirectory(directoryPath);
     }
 }
Exemplo 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("\\")));
             }
         }
     }
 }
Exemplo n.º 5
0
 public static string[] GetFileNames(string directoryPath)
 {
     if (!DirFileHelper.IsExistDirectory(directoryPath))
     {
         throw new FileNotFoundException();
     }
     return(Directory.GetFiles(directoryPath));
 }
Exemplo 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();
        }
Exemplo 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);
            }
        }
Exemplo 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]);
         }
     }
 }
Exemplo 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;
     }
 }
Exemplo n.º 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);
        }
Exemplo 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);
 }
Exemplo n.º 12
0
 public static void ClearFile(string filePath)
 {
     File.Delete(filePath);
     DirFileHelper.CreateFile(filePath);
 }