Visual C# 中,如果要得到某个文件所在之文件路径字符串,可以利用 My.Computer.FileSystem.GetFiles 函式来掷回。接下来,通过字符串本身的 SubString 函式,将不必要的目录路径部分去除之后,就可以得到只有文件名称的字符串。利用循环的方式,顺序将目录中所有的文件都处理过之后,就可以得到某目录之下所有的文件名称之字符串集合,程序代码如下所示:

int pos;
string shortName;
Computer MyComputer = new Computer();

foreach(
string FlagFileName in MyComputer.FileSystem.GetFiles(
    MyComputer.FileSystem.CurrentDirectory +
@"Flags"))
{
    pos = FlagFileName.LastIndexOf(
@"") + 1;

   
// 取得移除前置路径之后的简短文件名称。
     shortName = FlagFileName.Substring(pos);
   

}

 

章立民研究室敬上

期待更多精彩,敬请关注:

http://www.china-pub.com/static/jsj_zlm_060824.html

 

 

相关文章:

  • 2021-12-04
  • 2021-09-22
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-05-13
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案