请教如何使用C#做出Dos中的dir命令,实现dir功能与"dir /s"功能

catpk 2008-02-01 10:21:59
请教!
...全文
335 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
onthebox 2008-02-08
  • 打赏
  • 举报
回复
Mark!
Happy 鼠 Year!
catpk 2008-02-06
  • 打赏
  • 举报
回复
有人能用System.IO做出来么?
ChrisAK 2008-02-06
  • 打赏
  • 举报
回复
这个...
就是用System.IO下的那几个文件系统的类啊.
用一个递归算法就可以搞定的说...
wuyi8808 2008-02-06
  • 打赏
  • 举报
回复
春天的气息 2008-02-06
  • 打赏
  • 举报
回复
就是列示子目录吧,用递归呀!
lovexin 2008-02-02
  • 打赏
  • 举报
回复
happy
happy


欢迎大家来群里聊聊天....学习,,,研究....

C# / .Net 7729746 交流社团 聊技术,项目合作。

Blogs http://zhoufleru.cnblogs.com
jinjazz 2008-02-01
  • 打赏
  • 举报
回复
调用dir就不叫实现dir的功能了,Directory.GetFiles才是正确的,
如果你觉得一句话太简单完全可以自己写Directory.GetFiles

相关api 在kernel32.dll中
FindFirstFile
FindNextFile


这样的话就不叫用c#实现了,再深入的当然可以用汇编(这个正好是大学时候的汇编假期作业)
amandag 2008-02-01
  • 打赏
  • 举报
回复
内部命令貌似调用不了

可以参考

http://topic.csdn.net/t/20021101/15/1140291.html
lnwuyaowei 2008-02-01
  • 打赏
  • 举报
回复
using System;
using System.Text;
using System.Diagnostics;

namespace Wuya.GetDosCommandOutput
{
/// <summary>
/// DOS命令输出类
/// </summary>
class DosCommandOutput
{
/// <summary>
/// 执行DOS命令,返回DOS命令的输出
/// </summary>
/// <param name="dosCommand"> dos命令 </param>
/// <returns> 返回输出,假如发生异常,返回空字符串 </returns>
public static string Execute(string dosCommand)
{
return Execute(dosCommand, 60 * 1000);
}
/// <summary>
/// 执行DOS命令,返回DOS命令的输出
/// </summary>
/// <param name="dosCommand"> dos命令 </param>
/// <param name="milliseconds"> 等待命令执行的时间(单位:毫秒),假如设定为0,则无限等待 </param>



/// <returns> 返回输出,假如发生异常,返回空字符串 </returns>
public static string Execute(string dosCommand, int milliseconds)
{
string output = ""; //输出字符串
if (dosCommand != null && dosCommand != "")
{
Process process = new Process(); //创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe"; //设定需要执行的命令
startInfo.Arguments = "/C " dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false; //不使用系统外壳程序启动
startInfo.RedirectStandardInput = false; //不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true; //不创建窗口
process.StartInfo = startInfo;
try
{
if (process.Start()) //开始进程
{
if (milliseconds == 0)
process.WaitForExit(); //这里无限等待进程结束
else
process.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}
}
}
catpk 2008-02-01
  • 打赏
  • 举报
回复
不用这个直接调用的方法,谢谢!
he_8134 2008-02-01
  • 打赏
  • 举报
回复


//using System.IO
string[] allFilesInDPan=Directory.GetFiles(@"D:\", "*", SearchOption.AllDirectories);

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧