我需要使用C#打印文件夹中的文件名吗? [英] I need to print the name of files inside a folder using C#?

查看:82
本文介绍了我需要使用C#打印文件夹中的文件名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,该文件夹下有很多文本文件(* .txt).我正在开发一个必须打印带有时间戳的文本文件名称的网页.我正在使用aspx进行前端设计,并使用C#进行处理.如果有人指导我给C#打印带有时间戳的文本文件名称的代码块,那就太好了.

在此先感谢

I got a folder under which I have lot of text files (*.txt). I''m developing a web page which have to print the name of the text files with the time stamp. I''m using aspx for front-end design and C# for processing. It would be great if some guide me give the code block for C# printing the name of text files with time stamp.

Thanks in Advance

推荐答案

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("c:\\");
System.IO.FileInfo [] diar1 = dir.GetFiles();//获取目录内的所有文件列表
System.IO.FileInfo dra = null;

//列出指定目录中所有文件的名称
foreach(diar1中的System.IO.FileInfo dra_loopVariable){
dra = dra_loopVariable;
ListBox1.Items.Add(dra);
}
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("c:\\");
System.IO.FileInfo[] diar1 = dir.GetFiles();//get all list of files inside the directory
System.IO.FileInfo dra = null;

//list the names of all files in the specified directory
foreach (System.IO.FileInfo dra_loopVariable in diar1) {
dra = dra_loopVariable;
ListBox1.Items.Add(dra);
}


阅读这些页面,尝试混合您从那里学到的知识,然后编写自己的代码:

http://www.dotnetperls.com/directory-getfiles [ http://www.csharp-examples.net/file-creation-modification-time/ [< ^ ]

希望对您有所帮助.
Read these pages and try to mix what you have learn from there, and then write your own code :

http://www.dotnetperls.com/directory-getfiles[^]

http://www.csharp-examples.net/file-creation-modification-time/[^]

Hope it helps.


这篇关于我需要使用C#打印文件夹中的文件名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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