如何将计算机中的所有文件都列出到Visual C#中的列表框中? [英] how do you list all files from your computer to a listbox in visual C#?

查看:90
本文介绍了如何将计算机中的所有文件都列出到Visual C#中的列表框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个程序,将计算机中的所有文件列出到一个列表框中.我想制作一个易于使用的快速文件浏览器,使您可以从中打开并运行文件.谢谢.

I want to make a program that lists all the files in my computer into a listbox. I want to make a easy and fast to use file browser that allows you to open and run files from there. Thanks.

推荐答案

对于文件浏览器,您需要两件事

1.目录路径(用户选择的目录)
2.所有文件的列表.

for 1.需求,您可以使用FileBrowser,
而对于2.
您必须添加列表框并在下面的代码中加载所有文件列表,这将有所帮助

For File browser you need two thing

1. Directory path (Directory which user selects)
2. List of all file.

for 1. Requirement you can use FileBrowser,
and for 2.
you have to add list box and load all file list in the below code will help

//Here "c:\user\public\picture" is Directory path It can be any path form harddrive
string[] filePaths = Directory.GetFiles(@"c:\user\public\picture");
foreach (string m in filePaths)
{
    ListViewItem liv = new ListViewItem(m);
    listView1.Items.Add(liv);
}



最好的



All the Best


这篇关于如何将计算机中的所有文件都列出到Visual C#中的列表框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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