Exemplo n.º 1
0
 /// <summary>
 /// 复制文件夹
 /// </summary>
 /// <param name="strFromDirectory"></param>
 /// <param name="strToDirectory"></param>
 /// <returns></returns>
 public static bool CopyDir(string strFromDirectory, string strToDirectory)
 {
     Directory.CreateDirectory(strToDirectory);
     if (!Directory.Exists(strFromDirectory))
     {
         return(false);
     }
     string[] directories = Directory.GetDirectories(strFromDirectory);
     if (directories.Length > 0)
     {
         string[] array = directories;
         for (int i = 0; i < array.Length; i++)
         {
             string text = array[i];
             MdDirHelper.CopyDir(text, strToDirectory + text.Substring(text.LastIndexOf("\\")));
         }
     }
     string[] files = Directory.GetFiles(strFromDirectory);
     if (files.Length > 0)
     {
         string[] array2 = files;
         for (int j = 0; j < array2.Length; j++)
         {
             string text2 = array2[j];
             File.Copy(text2, strToDirectory + text2.Substring(text2.LastIndexOf("\\")));
         }
     }
     return(true);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 获取指定目录中所有文件列表
 /// </summary>
 /// <param name="directoryPath"></param>
 /// <returns></returns>
 public static string[] GetFileNames(string directoryPath)
 {
     if (!MdDirHelper.IsExistDirectory(directoryPath))
     {
         throw new FileNotFoundException();
     }
     return(Directory.GetFiles(directoryPath));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 检测指定目录是否为空
 /// </summary>
 /// <param name="directoryPath"></param>
 /// <returns></returns>
 public static bool IsEmptyDirectory(string directoryPath)
 {
     string[] fileNames = MdDirHelper.GetFileNames(directoryPath);
     if (fileNames.Length > 0)
     {
         return(false);
     }
     string[] dirs = MdDirHelper.GetDirs(directoryPath);
     return(dirs.Length <= 0);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 获取指定目录及子目录中所有文件列表
 /// </summary>
 /// <param name="directoryPath"></param>
 /// <param name="searchPattern"></param>
 /// <param name="isSearchChild"></param>
 /// <returns></returns>
 public static string[] GetFileNames(string directoryPath, string searchPattern, bool isSearchChild)
 {
     if (!MdDirHelper.IsExistDirectory(directoryPath))
     {
         throw new FileNotFoundException();
     }
     if (isSearchChild)
     {
         return(Directory.GetFiles(directoryPath, searchPattern, SearchOption.AllDirectories));
     }
     return(Directory.GetFiles(directoryPath, searchPattern, SearchOption.TopDirectoryOnly));
 }
Exemplo n.º 5
0
 /// <summary>
 /// 检测指定目录中是否存在指定的文件
 /// </summary>
 /// <param name="directoryPath"></param>
 /// <param name="searchPattern"></param>
 /// <param name="isSearchChild"></param>
 /// <returns></returns>
 public static bool ContainFile(string directoryPath, string searchPattern, bool isSearchChild)
 {
     string[] fileNames = MdDirHelper.GetFileNames(directoryPath, searchPattern, true);
     return(fileNames.Length != 0);
 }