您当前的位置: 首页 >  c#

刘一哥GIS

暂无认证

  • 4浏览

    0关注

    934博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#遍历一个文件夹下的所有可执行文件

刘一哥GIS 发布时间:2015-06-08 20:55:49 ,浏览量:4

using System;
using System.IO;

namespace IO操作
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(File.Exists(@"C:\IO.txt"));
            Console.WriteLine(Directory.Exists(@"C:\"));
            Console.WriteLine();

            //获取一个路径下所有可执行文件(.exe)
            string path = ".";//获取当前路径
            if (args.Length > 0)
            {
                if(Directory.Exists(args[0]))
                    path = args[0];//从外部获取的参数
                else
                    Console.WriteLine("{0} is not found", args[0]);
            }
            DirectoryInfo dir=new DirectoryInfo(path);
            foreach(FileInfo f in dir.GetFiles("*.exe"))
            {
                string name=f.Name;
                long size=f.Length;
                DateTime time=f.CreationTime;
                Console.WriteLine("{0,-12:N0}{1,-20:g}{2}",size,time,name);
            }

        }
    }
}
关注
打赏
1665586602
查看更多评论
立即登录/注册

微信扫码登录

0.3280s