IO DirectoryInfo MoveTo 将某一个文件或目录移到以一个目录
1.使用DirectoryInfo.MoveTo时,将目标文件夹一定要是不存在,不然报错。
代码如下:
View 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 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.将文件复制到另外一个目录中
代码如下:
View 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);
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);