cmd运行exe程序小Demo

时间:2022-09-02 15:55:49

1.C#代码

static void Main(string[] args)
{
string path = ".";
if (args.Length > 0)
{
if (Directory.Exists(args[0]))
{
path
= args[0];
}
}

DirectoryInfo di
= new DirectoryInfo(path);
foreach (var item in di.GetFiles("*.txt"))
{
string name = item.Name;
long size = item.Length;
DateTime createDate
= item.CreationTime;
Console.WriteLine($
"Name:{name},Size:{size},CreateDate:{createDate}");
}
}

2.生成

3.在项目运行文件夹下创建测试txt文件

cmd运行exe程序小Demo

 

4.Ctrl+R,输入cmd,确定

输入命令,回车:(切换存储盘)

d:

输入命令,回车:

cd D:\代码\疯狂代码\XJBX\ConsoleApp1\ConsoleApp6\bin\Debug

输入命令,回车:

ConsoleApp6.exe D:\代码\疯狂代码\XJBX\ConsoleApp1\ConsoleApp6\bin\Debug\test.txt

cmd运行exe程序小Demo

 

5.控制台上输出结果,完成小demo