c# 中循环遍历所有文件夹下的文件
2016-10-23 16:56
260 查看
</pre><p></p><p><span style="font-size:24px;color:#00cccc;">最近,在做文档管理系统,需要遍历文件夹下所有的文件(包括子文件里的文件),因为新手,所以博主就把方法写在这里,请大家参阅,欢迎批评指正。</span></p><p><span style="font-size:24px;color:#ff6666;"></span></p><p><span style="font-size:24px;color:#ff6666;">前台代码---------------------------------</span></p><p></p><pre name="code" class="csharp"><Window x:Class="document_manage.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:document_manage" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <ListBox x:Name="listBox" HorizontalAlignment="Left" Height="184" Margin="70,36,0,0" VerticalAlignment="Top" Width="394"/> <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="202,263,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="-0.307,0.364" Click="button_Click"/> </Grid> </Window> </span>
前台效果图:
后台代码-------------------
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace document_manage { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } //扫描路径 DirectoryInfo theFolder = new DirectoryInfo(@"F:\Fighting\python\"); private void button_Click(object sender, RoutedEventArgs e) { scan(theFolder); } //扫描方法 private void scan(FileSystemInfo info) { if (!info.Exists) return; DirectoryInfo dir = info as DirectoryInfo; //不是目录 if (dir == null) return; FileSystemInfo[] files = dir.GetFileSystemInfos(); for(int i =0; i< files.Length;i++) { FileInfo file = files[i] as FileInfo; //是文件 if (file != null) { listBox.Items.Add("名字: " + file.Name + ", 创建时间: " + file.CreationTime + ", 扩展名: " + file.Extension + ", 上次访问时间: " + file.LastAccessTime); } else scan(files[i]); } }//end scan } }
效果图:
相关文章推荐
- C#遍历文件夹下的所有文件
- java 循环遍历文件夹下面的所有文件
- C#遍历指定文件夹中的所有文件
- asp.net(C#)遍历文件夹下所有文件,绑定到GRIDVIEW并排序
- C#利用DirectoryInfo遍历文件夹所有文件的类
- C#遍历指定文件夹中的所有文件
- C#遍历指定文件夹中的所有文件
- C#遍历指定文件夹中的所有文件
- C#遍历指定文件夹中的所有文件
- C#遍历指定文件夹中的所有文件
- 【转】C#遍历指定文件夹中的所有文件
- C#遍历文件夹中的所有文件
- C# 删除、遍历指定目录下的所有指定文件、文件夹
- 遍历某文件夹下的所有文件 C#
- C#.Net遍历远程文件夹下的所有文件
- C#.Net遍历本地文件夹下的所有文件
- C# 遍历目录下所有文件夹下的文件
- C#遍历文件夹下的所有文件及文件夹
- c#遍历一个文件夹下的所有文件包括子文件夹
- C#遍历指定文件夹中的所有文件