Blogger Information
Blog 110
fans 0
comment 0
visits 112279
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
C#获取文件夹下的文件名
Coco
Original
7922 people have browsed it

  一、获取文件夹下面的文件名

  //文件夹路径

  String path=@"D:\myFile\Log";

  //方法一

  var files=Directory.GetFiles(path, "*.log");

  foreach (var file in files)

  Console.WriteLine(file); //控制台输出Log文件夹下面所有后缀为.log的文件名

  //方法二

  DirectoryInfo folder=new DirectoryInfo(path);

  foreach (FileInfo file in folder.GetFiles("LOG-"+now+"*.log"))

  {

  Console.WriteLine(file.FullName);

  }

  二、手游卖号平台应用

  例子:获取error-开头的文件个数

  String path=@"D:\myFile\Log";

  //第一种方法

  var files=Directory.GetFiles(path, "error-*.log");

  foreach (var file in files)

  count++;

  // 第二种方法

  DirectoryInfo folder=new DirectoryInfo(path);

  foreach (FileInfo file in folder.GetFiles("error-*.log"))

  {

  count++;

  }

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post