IO DirectoryInfo MoveTo 将某一个文件或目录移到以一个目录

本文详细介绍了在编程中使用DirectoryInfo.MoveTo方法移动文件夹和使用FileInfo.CopyTo方法复制文件的注意事项,包括目标文件夹必须不存在及文件复制过程中的创建文本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.使用DirectoryInfo.MoveTo时,将目标文件夹一定要是不存在,不然报错。

 代码如下:

ExpandedBlockStart.gifView Code
1    string path = @"c:\wtqCreate";
2             string pathTxt = path + @"\my.txt";
3             string wtqPath = @"c:\wtq";
4             string wttqq = @"c:\wttq11";
5             DirectoryInfo di = new DirectoryInfo(path);
6             di.MoveTo(wttqq);

 

 

 2.将文件复制到另外一个目录中

代码如下:

ExpandedBlockStart.gifView Code
1  string path = @"c:\wttq\Fireworks 2.bmp";
2             string destinationPath = @"c:\wtq\wtq1.bmp";
3             FileInfo fi = new FileInfo(path);
4             if (!fi.Exists)
5             {
6                 fi.CreateText();
7             }
8             fi.CopyTo(destinationPath);

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值