zoukankan      html  css  js  c++  java
  • 如何获取文件夹下各子文件夹名,同时将这些信息输出到文本文件中呢?求赐教!

    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_allDaZhongDianPingBeiJing_dazhongDaZhongDianPing_yonghuinx86Debug用户点评";///根文件夹地址   
              DirectoryInfo dif = new DirectoryInfo(path);///文件夹实例        

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

            string path1 = @"F:data_allce_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();///记数超过子文件夹数后,停止写入关闭流;               

          }                                    

    }      

       }   

      }

    }

    北卿~~~~
  • 相关阅读:
    Qt调用外部程序QProcess通信
    QT错误:collect2:ld returned 1 exit status
    ARM编译空间属性(转)
    深入C语言内存区域分配(进程的各个段)详解(转)
    Linux系统的组成和内核的组成
    C语言中,头文件和源文件的关系(转)
    Ubuntu安装samba服务器
    2018年应该做的事
    生活经历1
    学习笔记
  • 原文地址:https://www.cnblogs.com/Lxiaojiang/p/3568781.html
Copyright © 2011-2022 走看看