using System.IO;
public void creatPicPath()
{
string dirPath = HttpContext.Current.Server.MapPath("ChartImages");
string dirPathNew = Request.ServerVariables["APPL_PHYSICAL_PATH"] + "PrintOut\\newImg";
if (Directory.Exists(dirPath))
{
//获得目录信息
DirectoryInfo dir = new DirectoryInfo(dirPath);
//获得目录文件列表
FileInfo[] files = dir.GetFiles("*.png");
string[] fileNames = new string[files.Length];
int i = 0;
foreach (FileInfo fileInfo in files)
{
fileNames[i] = fileInfo.Name;
i++;
string fileName = fileInfo.Name;
string targetPath = dirPathNew;//复制同样一个文件放在待上传的目录下
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
else
{
string sourceFile = System.IO.Path.Combine(dirPath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
//获得目录信息
DirectoryInfo dirNew = new DirectoryInfo(dirPathNew);
//获得目录文件列表
FileInfo[] filesNew = dirNew.GetFiles("*.png");
string[] fileNamesNew = new string[filesNew.Length];
int ii = 0;
foreach (FileInfo fileInfoNew in filesNew)
{
fileNamesNew[ii] = fileInfoNew.Name;
System.IO.File.Delete(destFile);
ii++;
}
System.IO.File.Copy(sourceFile, destFile, true);
}
}
}
}