Ejemplo n.º 1
0
        public static void CopyDir(string srcPath, string aimPath, ISftpHelper helper)
        {
            try
            {
                // 检查目标目录是否以目录分割字符结束如果不是则添加之
                if (!aimPath[aimPath.Length - 1].Equals(helper.DefPath))
                    aimPath += helper.DefPath;
                // 判断目标目录是否存在如果不存在则新建之
                if (!helper.DirExist(aimPath))
                {
                    helper.Mkdir(aimPath);
                }

                // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
                //如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
                //string[] fileList = Directory.GetFiles(srcPath);
                string[] fileList = Directory.GetFileSystemEntries(srcPath);
                //遍历所有的文件和目录
                foreach (string file in fileList)
                {
                    //先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
                    if (Directory.Exists(file))
                        CopyDir(file, aimPath + Path.GetFileName(file), helper);
                    //否则直接Copy文件
                    else
                        //File.Copy(file, aimPath + Path.GetFileName(file), true);
                        helper.Put(file, aimPath + Path.GetFileName(file));
                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.ToString());
            }
        }
Ejemplo n.º 2
0
        public static void CopyDir(string path, ref List<FileInfo> fileList, ISftpHelper helper)
        {
            if (!Directory.Exists(path)) return;
            DirectoryInfo dir = new DirectoryInfo(path);
            //不是目录
            FileSystemInfo[] files = dir.GetFileSystemInfos();
            for (int i = 0; i < files.Length; i++)
            {
                FileSystemInfo file = files[i];

                //是文件
                if ((file.Attributes & FileAttributes.Directory) == 0)
                    fileList.Add((FileInfo)file);
                //对于子目录,进行递归调用
                else
                    ListFiles(files[i].FullName, ref fileList);
            }
        }
Ejemplo n.º 3
0
 public static void CopyDir(string srcPath, string aimPath, ISftpHelper helper, Action<int, string> ShowMessage)
 {
     try
     {
         // 检查目标目录是否以目录分割字符结束如果不是则添加之
         if (!aimPath[aimPath.Length - 1].Equals(helper.DefPath))
             aimPath += helper.DefPath;
         // 判断目标目录是否存在如果不存在则新建之
         if (!helper.DirExist(aimPath))
         {
             helper.Mkdir(aimPath);
         }
         DirectoryInfo dir = new DirectoryInfo(srcPath);
         //是文件
         if ((dir.Attributes & FileAttributes.Directory) == 0)
         {
             helper.Put(srcPath, aimPath + Path.GetFileName(srcPath));
             ShowMessage(0, srcPath + "-->" + aimPath + Path.GetFileName(srcPath));
         }
         // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
         //如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
         //string[] fileList = Directory.GetFiles(srcPath);
         string[] fileList = Directory.GetFileSystemEntries(srcPath);
         //遍历所有的文件和目录
         foreach (string file in fileList)
         {
             //先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
             if (Directory.Exists(file))
                 CopyDir(file, aimPath + Path.GetFileName(file), helper, ShowMessage);
             //否则直接Copy文件
             else
             {
                 helper.Put(file, aimPath + Path.GetFileName(file));
                 ShowMessage(0, file + "-->" + aimPath + Path.GetFileName(file));
             }
         }
     }
     catch (Exception ee)
     {
         throw new Exception(ee.ToString());
     }
 }