首页 > 其他 > 详细

如何获取文件夹下各子文件夹名,同时将这些信息输出到文本文件中呢?求赐教!

时间:2014-02-27 06:02:56      阅读:522      评论:0      收藏:0      [点我收藏+]

using System;

using System.Collections.Generic;

using System.Linq; using System.Data;

using System.Configuration;

using System.Collections;

using System.Net;

using System.Text;

using System.IO;

using System.Text.RegularExpressions;

using System.Diagnostics;

namespace zheng_li

{     class Program  

   {       

  static void Main(string[] args)    

     { 
        string path = @"F:\data_all\DaZhongDianPing\BeiJing_dazhong\DaZhongDianPing_yonghu\bin\x86\Debug\用户点评";///根文件夹地址   
          DirectoryInfo dif = new DirectoryInfo(path);///文件夹实例        

         FileSystemInfo[]fsis = dif.GetFileSystemInfos();////获取子文件夹          

        string path1 = @"F:\data_all\ce_shi.txt";///定义新的文件路径            

        FileInfo f1 = new FileInfo(path1);           

       f1.Create();///创建文件        

       int count=0;               

  foreach (FileSystemInfo fsi in fsis)            

     {      DirectoryInfo dif1 = new DirectoryInfo(fsi.FullName);              

           string str = dif1.Name;///子文件夹名                    

           Console.WriteLine(str);                       

           FileStream fs = new FileStream(path1, FileMode.Open,FileAccess.ReadWrite);                       

          StreamWriter sr = new StreamWriter(fs);                     

          sr.Write(str);///流写入创建的文件中                        

          count += 1;   //// 记数,一共多少个子文件夹                           

     if(count>7254)             

        { sr.Close();                     

          fs.Close();///记数超过子文件夹数后,停止写入关闭流;               

      }                                    

}      

   }   

  }

}

如何获取文件夹下各子文件夹名,同时将这些信息输出到文本文件中呢?求赐教!,布布扣,bubuko.com

如何获取文件夹下各子文件夹名,同时将这些信息输出到文本文件中呢?求赐教!

原文:http://www.cnblogs.com/Lxiaojiang/p/3568781.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!