循环遍历文件夹
来源:互联网 发布:美国进口数据查询 编辑:程序博客网 时间:2024/06/05 09:41
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("输入路径:");
string path = Console.ReadLine();
string[] ds = null;//获取路径
int dslength = 1;//循环判断
int count; //获取到文件夹个数
StringBuilder sb = new StringBuilder();
int r = 0;//判断根路径加载一遍
string DirectoryName = null;
string s = null;
Dictionary<int, string> da = null;
while (dslength > 0)
{
if (r == 0)
{
sb.Append(@"" + path + ":");
ds = SelectItem.GetItem(sb.ToString());
}
else
{
ds = SelectItem.GetItem(DirectoryName);
}
da = SelectItem.Diction(ds, out count);
if (count < 0)
{
Console.WriteLine("该文件没有文件夹");
}
Console.WriteLine("请选择文件夹");
s = SelectItem.SlectValue(count);
DirectoryName = da[Convert.ToInt32(s)].ToString();
r = 1;
}
}
}
class SelectItem
{
public static string[] GetItem(string path)
{
//DirectoryInfo di = new DirectoryInfo(path);
//FileSystemInfo[] fs = di.GetFileSystemInfos();
//string[] st = new string[fs.Length];
//for (int i = 0; i < fs.Length; i++)
//{
// st[i] = fs[i].ToString();
//}
//return st;
string[] st = Directory.GetDirectories(path);
return st;
}
internal static Dictionary<int, string> Diction(string[] ds, out int count)
{
int len= ds.Length;
Dictionary<int, string> da =null;
if (len == 0)
{
count = -1;
}
else
{
da= new Dictionary<int, string>();
Console.WriteLine("您选择的目录中包含的文件夹有:");
for (int i = 0; i < len; i++)
{
da.Add(i, ds[i]);
}
foreach (KeyValuePair<int, string> var in da)
{
int a = var.Key;
string b = var.Value;
Console.WriteLine(a + "--" + b);
}
count = da.Count;
}
return da;
}
public static string SlectValue(int count)
{
bool bo = true;
string s = null;
do
{
s = Console.ReadLine();
int result = -1;
if (int.TryParse(s, out result))
{
if (Convert.ToInt32(s) < 0 || Convert.ToInt32(s) > (count - 1))
{
Console.WriteLine("你选择的编号有误,请重新输入!");
}
else
{
bo = false;
}
}
else
{
Console.WriteLine("输入字符串格式不正确!");
}
} while (bo);
return s;
}
}
}
- 循环遍历文件夹
- 循环方式遍历文件夹
- 循环遍历文件夹
- 文件夹复制操作(非递归循环遍历文件夹) C#
- java循环遍历文件夹及其子文件夹和文件
- 文件夹复制操作(非递归循环遍历文件夹)
- Asp.net循环遍历服务器文件夹及文件
- Asp.net循环遍历服务器文件夹及文件
- php循环遍历所有的文件即文件夹
- c# 中循环遍历所有文件夹下的文件
- 循环遍历某个文件夹下面的所有文件,递归方法
- java循环遍历文件夹出现的bug记录
- 遍历文件夹
- 遍历文件夹
- 遍历文件夹
- 遍历文件夹
- 遍历文件夹
- 文件夹遍历
- 遥感的几何校正、正射校正、辐射校正
- Visual Studio 2008 每日提示(三十)
- 和T的老外聊的高兴,A的电话技术面试真难
- 嵌入式Linux操作系统学习规划
- 关于log4j.properties详细配置
- 循环遍历文件夹
- Flex 开发入门
- 获取Linux 2.6.x sys_call_table
- SetTimer函数的用法——转载 发布时间: 2006-5-22 下午5:26
- 如果你想让你的IIS支持WAP
- 自定义排序函数实现时需要注意的问题
- 成员函数的重载、覆盖与隐藏
- GUID( create and string covert)
- rename.js