惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Fortinet All Blogs
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
小众软件
小众软件
有赞技术团队
有赞技术团队
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
AWS News Blog
AWS News Blog
C
Cisco Blogs
美团技术团队
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
W
WeLiveSecurity
D
DataBreaches.Net
博客园 - 司徒正美
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
Vercel News
Vercel News
月光博客
月光博客
T
Tailwind CSS Blog
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
V2EX
WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
Recent Announcements
Recent Announcements

博客园 - pysharp

openstack horizon api step by step understanding horizon's template path what can PsTools\psexec do! - pysharp What's New in Python3.0 - pysharp [转]利用adsutil.vbs脚本创建自定义web站点 我的2008. sql基础篇,不断更新中...... TypeConvert Demo javascript 调试器v1.0.0.0 Dundas Chart Demo For New User - pysharp c#面向对象中的继承初步认识 .net 集合类初步认识 c# 文件操作类 - pysharp - 博客园 关于urlrewrite的小DEMO - pysharp - 博客园 c# 动态编译方法 c# 读取Excel到datable asp.net 下载和在线预览Excel的方法 排序算法 c#实现 简单使用nHibernate,新手练习用。
c# 目录操作类
pysharp · 2008-03-21 · via 博客园 - pysharp

/// <summary>
    /// 目录操作类
    /// </summary>
    public class DirectoryHelper
    {
        public DirectoryHelper()
        { }

        /// <summary>
        /// 得到所有磁盘驱动器
        /// </summary>
        /// <returns></returns>
        public string[] AllDrivers()
        {
            return Directory.GetLogicalDrives();
        }

        /// <summary>
        /// 应用程序的当前工作目录,bin文件夹
        /// </summary>
        /// <returns></returns>
        public string CurrentDirectory()
        {
            return Directory.GetCurrentDirectory();
        }

        /// <summary>
        /// 获取path目录下的文件,不包括文件夹
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public string[] AllFiles(string path)
        {
            return Directory.GetFiles(path);
        }

        /// <summary>
        /// 创建一个目录如果directory存在,那么就不创建了目录了
        /// </summary>
        /// <param name="directory"></param>
        public void CreateDirectory(string directory)
        {
            //DirectoryInfo info = new DirectoryInfo(directory);        
            //info.Create();  

            DirectoryInfo info = Directory.CreateDirectory(directory);
        }

        /// <summary>
        /// 删除目录
        /// </summary>
        /// <param name="path"></param>
        public void DeleteDirectory(string path)
        {
            //Directory.Delete(path, false/*删除子目录*/);   //子目录非空则报错。

            Directory.Delete(path, true/*保留子目录*/);  //忽略子目录内容,有没有内容都删除
        }

        /// <summary>
        /// 目录下的所有文件,隐藏文件也可见,偷窥吗?
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public string[] AllContent(string path)
        {
            return Directory.GetFileSystemEntries(path);//如果path不存在则报错
        }

        /// <summary>
        /// 复制文件目录,复制完成原目录删除
        /// </summary>
        /// <param name="path1"></param>
        /// <param name="path2"></param>
        public void CopyDirectory(string sourcePath/*复制前必须存在,复制完成后挂掉了*/,string targetPath/*复制前不能存在*/)
        {
            Directory.Move(sourcePath,targetPath);
        }

        /// <summary>
        /// 编码,说实话我没用过,不知道干吗用.
        /// </summary>
        /// <returns></returns>
        public string Codeing()
        {
            Encoding code = Encoding.Default;
            //byte[] bytes = code.GetBytes("中华人民共和国");    
            byte[] bytes = code.GetBytes("i'm a smart boy");     
            return Encoding.GetEncoding("UTF-8").GetString(bytes);       //doc环境不支持中文吗?中文不能正常转回去,英文就可以。
        }
    }