如何在C#中获取文件夹详细信息和子文件夹/文件详细信息 [英] How to get folder details and sub folders / files details in C#

查看:357
本文介绍了如何在C#中获取文件夹详细信息和子文件夹/文件详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C的新手#

我使用 folderBrowserDialog 设置文件夹路径,我想知道如何获取它是文件夹名称和大小。我还需要子文件夹的名称,大小

以及子文件夹中所有文件的名称和大小

C#/ Windows表单应用程序



感谢提前!

解决方案

Hello Manoj,



使用FolderBrowserDialog尝试此视频以获取有关基本操作的帮助:

C#初学者教程 - 56 - FolderBrowserDialog [ ^ ]







[update]



请注意,在您发布的代码示例中,您不断更新相同的 richTextBox1.Text 再一次,显然你会只看到最后一个文件的信息!

  foreach  var 文件  allFiles)
{
richTextBox1.Text = file.Name + + file.Length;
}

[/ update]







祝你好运,

Edo


这里没有人不提供你想要的确切代码。你当你遇到困难时需要尝试自己来这里。从这里开始,这将对你有所帮助..

C#中FolderBrowserDialog的示例 [ ^ ]

http://onemancoder.wordpress.com/2012/01/27/a-better-folderbrowserdialog-in-c/ [ ^ ]

ht tp://www.c-sharpcorner.com/uploadfile/mahesh/folderbrowserdialog-in-C-Sharp/ [ ^ ]


没有简单的单一命令可以做到这一点 - 但它并不难。唯一的复杂因素是当您遍历文件夹时避免处理系统文件和文件夹(如果这样做,将抛出异常):

 私有  bool  IsIgnorable( string  dir)
{
if (dir.EndsWith( :System Volume Information )) return true ;
if (dir.Contains(

I'm new to C#
I set the folder path using folderBrowserDialog and i want to know how to get it's folder name and size. i also need sub folder's names , size.
and all file's names and size in sub folders
C# / Windows form application

THANK IN ADVANCE!

解决方案

Hello Manoj,

Try this video for help on basic actions with the FolderBrowserDialog:
C# Beginners Tutorial - 56 - FolderBrowserDialog[^]



[update]

Notice that in the code sample you posted you keep updating the same richTextBox1.Text over and over again, so obviously you will only see the last file's information!

foreach (var file in allFiles)
{
    richTextBox1.Text = file.Name + " " + file.Length;
}

[/update]



Good luck,
Edo


No one here don't give exact codes of what you want.You need to try yourself and come here when you get stuck.Have a start from here which will help you a lot..
Example for FolderBrowserDialog in C#[^]
http://onemancoder.wordpress.com/2012/01/27/a-better-folderbrowserdialog-in-c/[^]
http://www.c-sharpcorner.com/uploadfile/mahesh/folderbrowserdialog-in-C-Sharp/[^]


There is no simple single command to do that - but it isn't that difficult. The only complication is avoiding processing system files and folders when you iterate through folders (if you do, an exception will be thrown):

private bool IsIgnorable( string dir )
    {
    if (dir.EndsWith( ":System Volume Information" )) return true;
    if (dir.Contains( ":


这篇关于如何在C#中获取文件夹详细信息和子文件夹/文件详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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