1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| class Program { static void Main(string[] args) { //在D盘下创建code文件夹 Directory.CreateDirectory("D:\\directoryInfo"); FileInfo fileInfo = new FileInfo("D:\\directoryInfo\\test1.txt"); if (!fileInfo.Exists) { //创建文件 fileInfo.Create().Close(); } fileInfo.Attributes = FileAttributes.Normal;//设置文件属性 Console.WriteLine("文件路径:"+ fileInfo.Directory); Console.WriteLine("文件名称:"+ fileInfo.Name); Console.WriteLine("文件是否只读:"+ fileInfo.IsReadOnly); Console.WriteLine("文件大小:" +fileInfo.Length); //先创建code-1 文件夹 //将文件移动到code-1文件夹下 Directory.CreateDirectory("D:\\directoryInfo-1"); //判断目标文件夹中是否含有文件test1.txt FileInfo newFileInfo = new FileInfo("D:\\directoryInfo-1\\test1.txt"); if (!newFileInfo.Exists) { //移动文件到指定路径 fileInfo.MoveTo("D:\\directoryInfo-1\\test1.txt"); } } }
|