c#实现文件剪切

firestone1986 2007-09-10 02:05:13
求救C#实现视频剪切的代码
...全文
1177 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxiju203 2011-06-16
  • 打赏
  • 举报
回复
剪切其实就是先拷贝文件 验证拷贝无误以后将源文件删除
zm1988214 2011-06-16
  • 打赏
  • 举报
回复
public void CopyDir(string Ddir, string Sdir, int intflag)
{
DirectoryInfo dir = new DirectoryInfo(Sdir);
string SbuDir = Ddir;
try
{
if (!dir.Exists) //判断所指的文件或文件夹是否存在
{
return;
}
DirectoryInfo dirD = dir as DirectoryInfo; //如果给定参数不是文件夹则退出
string UpDir = Directory.GetParent(Ddir).FullName;
if (dirD == null) //判断文件夹是否为空
{
Directory.CreateDirectory(UpDir + "\\" + dirD.Name); //如果为空,创建文件夹并退出
return;
}
else
{
Directory.CreateDirectory(UpDir + "\\" + dirD.Name);
}
SbuDir = UpDir + "\\" + dirD.Name + "\\";
FileSystemInfo[] files = dirD.GetFileSystemInfos();//获取文件夹中所有文件和文件夹
//对单个FileSystemInfo进行判断,如果是文件夹则进行递归操作
foreach (FileSystemInfo FSys in files)
{
FileInfo file = FSys as FileInfo;
if (file != null) //如果是文件的话,进行文件的复制操作
{
FileInfo SFInfo = new FileInfo(file.DirectoryName + "\\" + file.Name);
//获取文件所在的原始路径
SFInfo.CopyTo(SbuDir + "\\" + file.Name, true);//将文件复制到指定的路径中
}
else
{
string pp = FSys.Name; //获取当前搜索到的文件夹名称
CopyDir(SbuDir + FSys.ToString(), Sdir + "\\" + FSys.ToString(),intflag);
//如果是文件,则进行递归调用
}
}
if (intflag == 1)
Directory.Delete(Sdir, true);
}
catch
{
MessageBox.Show("对不起,复制文件夹失败!");
}
}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧