创建一个新文件
Directory.CreateDirectory(@"C: UsersenleDesktop ew");//路径 Console.WriteLine("创建成功");
Console.ReadKey()
删除一个文件
Directory.Delete(@"C: UsersenleDesktop ew", true); Console.WriteLine("删除成功");
Console.ReadKey()
剪切一个文件
Directory.Move(@"C:UsersenleDesktop ew", @"C:UsersenleDesktop ew1"); Console.Write("剪切成功");
Console.ReadKey()
读取文件所有文件的全路径
string[] path = Directory.GetFiles(@"C:UsersenleDesktop2", "*.pdf");//"*.pdf" 对读取文件的格式,进行限定 for (int i = 0; i < path.Length; i++) { Console.WriteLine(path[i]); }
文件夹的路径
string[] path = Directory.GetDirectories(@"C:UsersenleDesktop2"); for (int i = 0; i < path.Length; i++) { Console.WriteLine(path[i]); }
Console.ReadKey()
创建100个文件夹
if (Directory .Exists (@"C:UsersenleDesktop ew1")) { for (int i = 0; i < 100; i++) { Directory.CreateDirectory(@"C: UsersenleDesktop ew1" + i); } Console.WriteLine("OK");
Console.ReadKey();