C#解压缩.vps文件,复制指定文件到指定目录下

        private void SearchFwdcd()
        {
            int i=0;
            string Temp=Path.Combine("C:\\", "Fwdcd");
            //开始前验证相关设置是否开启
            /*if (BdcApplication.Instance.CurrentProject == null)
            {
                MessageUtil.ShowMessage("请先设置不动产项目");
                return;
            }*/
            string workspacePath;
            string basePath;
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            folderBrowserDialog.ShowNewFolderButton = false;
            folderBrowserDialog.Description="请选择.vps数据所在目录";
            DialogResult d = folderBrowserDialog.ShowDialog();
            if (d == DialogResult.OK)
            {
                basePath = folderBrowserDialog.SelectedPath;
                string[] files = Directory.GetFiles(basePath, "*.vps", SearchOption.AllDirectories);
                if (files.Length == 0)
                {
                    MessageUtil.ShowMessage("未查找到.vps文件");
                    return;
                }
                foreach (string file in files)
                {
                    SplashScreenManager.ShowDefaultWaitForm("请等待", "正在处理数据...");
                    string temp = Path.Combine(BdcApplication.Instance.CurrentProject.RootPath, "New");
                    if (!Directory.Exists(temp))
                    {
                        Directory.CreateDirectory(temp);
                    }
                    try
                    {
                        SharpZip.UnpackFiles(file, temp);
                    }
                    catch (Exception e)
                    {
                        MessageUtil.ShowWarning(string.Format("{0}数据存在问题,不能解压缩!", Path.GetDirectoryName(file)));
                        FileOperateHelper.DeleteFolder(temp);
                        SplashScreenManager.CloseDefaultWaitForm();
                        continue;
                    }
                    i++;
                    workspacePath = Path.Combine(temp, "Shapefile");
                    string[] dcd = Directory.GetFiles(workspacePath, "FWDCD.*");
                    if (dcd.Length == 0) return;
                    if (!Directory.Exists(Temp))
                    {
                        Directory.CreateDirectory(Temp);
                    }
                    foreach (string pro in dcd)
                    {
                        string tempName = string.Format("{0}\\{1}", Temp, DateTime.Now.ToString("yyyyMMddHHmmssff"));
                        string newFilePath = string.Format("{0}{1}", tempName, Path.GetFileName(pro));
                        dgCheckpath(tempName, newFilePath, pro);
                        FileOperateHelper.FileCoppy(pro, newFilePath);
                    }
                    FileOperateHelper.DeleteFolder(temp);
                }
                SplashScreenManager.CloseDefaultWaitForm();
                MessageUtil.ShowMessage(string.Format("操作已完成,共处理{0}条数据,存放地址为{1},请注意查收", i, Temp));
            }
            MessageUtil.ShowMessage("操作已取消");
        }
        /// <summary>
        /// 递归检查是否重名
        /// </summary>
        /// <param name="tempName"></param>
        /// <param name="newFilePath"></param>
        /// <param name="pro"></param>
        /// <returns></returns>
        private string dgCheckpath(string tempName, string newFilePath, string pro)
        {
            if (DirFileHelper.IsExistFile(newFilePath))
            {
                tempName = string.Format("{0}(1)", tempName);
                newFilePath = string.Format("{0}{1}", tempName, Path.GetFileName(pro));
                dgCheckpath(tempName, newFilePath, pro);
            }
            return newFilePath;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值