C# 文件copy和文件删除
public bool CopyFile(string SourcePath, string CopyPathFoder)
{
bool bfg = false;
if (!Directory.Exists(CopyPathFoder))
{
Directory.CreateDirectory(CopyPathFoder);
}
string[] childfile = SourcePath.Split('\\');
File.Copy(SourcePath, CopyPathFoder + @"\" + childfile[childfile.Length - 1], true);
bfg = true;
return bfg;
}
/// <summary>
/// 删除文件
/// </summary>
/// <param name="Path"></param>
/// <returns></returns>
public bool FileDel(string Path)
{
try
{
if (File.Exists(Path))
{
FileInfo fi = new FileInfo(Path);
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
{
fi.Attributes = FileAttributes.Normal;
}
File.Delete(Path);
return true;
}
}
catch (Exception)
{
return false;
}
return false;
}