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;
}
C#解压缩.vps文件,复制指定文件到指定目录下
最新推荐文章于 2023-01-28 17:58:03 发布