如何获取文件夹下各子文件夹名,同时将这些信息输出到文本文件中呢?求赐教!
2014-02-26 11:43
603 查看
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();///记数超过子文件夹数后,停止写入关闭流;
}
}
}
}
}
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();///记数超过子文件夹数后,停止写入关闭流;
}
}
}
}
}
相关文章推荐
- 如何获取文件夹里面的文本信息
- vc++调用exe时,如何获取exe的输出信息
- win32调试工具原理OutputDebugString以及如何获取输出信息
- vc++调用exe时,如何获取exe的输出信息(输出显示在IDE的输出中)
- Linux下的C程序如何调用系统命令,并获取系统的输出信息到C程序中
- Java 如何获取控制台日志输出的信息? WriterAppender 可以实现? 配置文件如何配置
- Log4j 如何实现 根据不同的类 或者不同的包 输出的调试信息到不同的文件夹中
- vc++调用exe时,如何获取exe的输出信息
- 如何获取shell命令输出的错误信息?
- 如何获取Windows命令行参数信息(和Linux中的ps -ef的输出相似)
- Total的Mapbasic教学-输出特定信息到一个文本文件和如何算出线的另一个端点
- 可否同时获取多个基站的信息,如何获取?
- Hadoop 多输入和多输出研究(如何在Job History中获取相关信息)
- FindFile FindNextFile 如何遍历一个文件夹并获取里面文件的信息
- vc++调用exe时,如何获取exe的输出信息
- c++里的system()函数调用系统命令如何获取打印信息
- 如何从代码中获取hibernate中配置的数据库方言信息
- 如何在SqlServer中获取前端连接的IP地址,计算机名等信息
- 如何获取mysql帮助信息
- 关于Linux下如何获取计算机的硬件信息