📄 movefile.cs
字号:
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
string path2 = @"c:\temp2\MyTest.txt";
try
{
if (!File.Exists(path))
{
using (FileStream fs = File.Create(path)) { }
}
//确定目标不存在
if (File.Exists(path2))
File.Delete(path2);
//移动文件
File.Move(path, path2);
Console.WriteLine("文件由{0}移动到{1}", path, path2);
//判断文件是否存在
if (File.Exists(path))
{
Console.WriteLine("源文件存在");
}
else
{
Console.WriteLine("源文件不存在");
}
}
catch (Exception e)
{
Console.WriteLine("操作取消:{0}", e.ToString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -