public void FolderCopy(string srcFolderPath, string destFolderPath)
{
//检查目标目录是否以目标分隔符结束,如果不是则添加之
if (destFolderPath[destFolderPath.Length - 1] != Path.DirectorySeparatorChar)
destFolderPath += Path.DirectorySeparatorChar;
//判断目标目录是否存在,如果不在则创建之
if (!System.IO.Directory.Exists(destFolderPath))
System.IO.Directory.CreateDirectory(destFolderPath);
string[] fileList = System.IO.Directory.GetFileSystemEntries(srcFolderPath);
foreach (string file in fileList)
{
if (System.IO.Directory.Exists(file))
FolderCopy(file, destFolderPath + Path.GetFileName(file));
else
{
FileInfo fi = new FileInfo(file);
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)//改变只读文件属性,否则删不掉
fi.Attributes = FileAttributes.Normal;
try
{ File.Copy(file, destFolderPath + Path.GetFileName(file), true); }
catch (Exception e)
{
WriteNotepad(e.Message+"6");
}
}
}
}
{
//检查目标目录是否以目标分隔符结束,如果不是则添加之
if (destFolderPath[destFolderPath.Length - 1] != Path.DirectorySeparatorChar)
destFolderPath += Path.DirectorySeparatorChar;
//判断目标目录是否存在,如果不在则创建之
if (!System.IO.Directory.Exists(destFolderPath))
System.IO.Directory.CreateDirectory(destFolderPath);
string[] fileList = System.IO.Directory.GetFileSystemEntries(srcFolderPath);
foreach (string file in fileList)
{
if (System.IO.Directory.Exists(file))
FolderCopy(file, destFolderPath + Path.GetFileName(file));
else
{
FileInfo fi = new FileInfo(file);
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)//改变只读文件属性,否则删不掉
fi.Attributes = FileAttributes.Normal;
try
{ File.Copy(file, destFolderPath + Path.GetFileName(file), true); }
catch (Exception e)
{
WriteNotepad(e.Message+"6");
}
}
}
}