显示文件夹的内容 [英] Show Contents of a Folder

查看:84
本文介绍了显示文件夹的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,



我正在制作一个小程序,只是为了获得如何做到这一点的经验,这是一个控制台程序。我只需要看起来像这样的东西:



  - 文件夹 -  
folder1
folder2
folder3

- 文件 -
file1
file2
file3





i我真的不确定如何开始这个。有人能给我一些源代码吗?谢谢!

解决方案

 DirectoryInfo di =  new  DirectoryInfo(  A:\\); 
var 目录= di.GetFiles( *,SearchOption.AllDirectories);

foreach (FileInfo d in 目录)
{
// 将文件添加到列表中,以便以后可以比较它们以查看每个文件
// 需要是否为copid
}



尝试以上代码



更多 get-all-files-and-directories-in-specific-path-fast [ ^ ]


< blockquote>查看文件类 [ ^ ]和目录类 [ ^ ]

以下是一些示例文章

在C#中使用文件类 [ ^ ]

使用.Net中的目录类(C#) [ ^ ]

C#中的Directory和DirectoryInfo类
[ ^ ]

C#FileInfo [ ^ ]

这可以帮助您入门。




试试这段代码,

 静态  void  Main( string  [] args)
{
string location = @ D:\Your_Location;
Console.WriteLine( 目录: + location);
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(location);
FullDirList(dir, *);
Console.ReadKey();
}
静态 void FullDirList(DirectoryInfo目录, string patternToSearch)
{
Console.WriteLine( );
Console.WriteLine(dir.Name);
Console.WriteLine( ********);
尝试
{
foreach (FileInfo f dir.GetFiles(patternToSearch))
{
Console.WriteLine(f.Name);
}
}
catch
{
Console.WriteLine( 无法访问目录{0} \ n !!!!,dir.FullName);
return ;
}
foreach (DirectoryInfo d in dir.GetDirectories())
{
FullDirList(d,patternToSearch);
}
}



这将显示给定目录中的所有文件夹和文件。这将显示子目录及其文件。



我希望这会有所帮助。

谢谢:)

hey guys,

i am making a small program just for experience on how to do this, this is a console program. i just need something that looks like this:

--Folders--
folder1
folder2
folder3

--Files--
file1
file2
file3



i am not really sure how to even get started on this. is someone able to give me some source code please? thanks!

解决方案

DirectoryInfo di = new DirectoryInfo("A:\\");
var directories= di.GetFiles("*", SearchOption.AllDirectories);

foreach (FileInfo d in directories)
{
       //Add files to a list so that later they can be compared to see if each file
       // needs to be copid or not
}


try above code

more at get-all-files-and-directories-in-specific-path-fast[^]


Take a look at the File Class[^] and Directory Class[^]
Here are some sample articles
Working With File Class in C#[^]
Working with Directory Class in .Net (C#)[^]
Directory and DirectoryInfo Classes in C#
[^]
C# FileInfo[^]
This should help you you to get started.


Hi,
Try this code,

static void Main(string[] args)
{
     string location = @"D:\Your_Location";
     Console.WriteLine("Directory: " + location);
     System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(location);
     FullDirList(dir, "*");
     Console.ReadKey();
}
static void FullDirList(DirectoryInfo dir, string patternToSearch)
{
     Console.WriteLine("");
     Console.WriteLine(dir.Name);
     Console.WriteLine("********");
     try
     {
          foreach (FileInfo f in dir.GetFiles(patternToSearch))
          {
               Console.WriteLine(f.Name);
          }
     }
     catch
     {
           Console.WriteLine("Directory {0}  \n could not be accessed!!!!", dir.FullName);
           return;
     }
     foreach (DirectoryInfo d in dir.GetDirectories())
     {
           FullDirList(d, patternToSearch);
     }
}


This will show all the folders and files in your given directory. This will show subdirectory and their files as well.

I hope this will help.
Thanks :)


这篇关于显示文件夹的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆