• c#几个常用的代码


    1、获取“我的文档”等一些系统文件夹路径
    Environment.SpecialFolder中包含了一些系统文件夹信息
    MessageBox.Show(Environment.GetFolderPath( Environment.SpecialFolder.Personal ));

    2、获取 硬盘临时文件夹
    this.p_runFilePath=System.Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)+@"\Content.IE5\aaa";

    3、获取应用程序当前执行的路径
    string appPath = Application.ExecutablePath;

    4、 如何确定当前运行的系统
    OperatingSystem os = Environment.OSVersion;
    MessageBox.Show(os.Version.ToString());
    MessageBox.Show(os.Platform.ToString());

    5、从完整的路径中获取文件名
    用System.IO.Path.GetFileName 和 System.IO.Path.GetFileNameWithoutExtension(无扩展名)的方法

    6、从完整的路径中获取文件扩展名
    用System.IO.Path.GetExtension方法

    7、被执行的EXE文件所在的目录。

    如果是WinForm,可以使用System.Windows.Forms.Application类提供的StartupPath属性。

    此外,AppDomain.CurrentDomain.BaseDirectory 属性也可以获得EXE文件所在的目录。

    Directory.GetCurrentDirectory(); 获取应用程序的当前工作目录,
    应该是应用程序最后一次操作过的目录。(比如在操作 OpenFileDialog 后就会改变。)
    最后一位[ 不 ]包括"\"

    AppDomain.CurrentDomain.BaseDirectory; 程序集的基目录,
    最后一位包括"\"

    string savingPath = AppDomain.CurrentDomain.BaseDirectory;
    if(!savingPath.EndsWith(@"\"))
    {
    savingPath += @"\";
    }
    savingPath += "TL_"+DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

    if(!Directory.Exists(savingPath))
    {
    Directory.CreateDirectory(savingPath);
    }

  • 相关阅读:
    二分和三分
    windows对拍及其应用
    RMQ与st表
    图论最短路
    图论最小生成树
    贪心问题
    [转载]图论500题
    第二次重建博客。。
    二分和三分题
    树状数组
  • 原文地址:https://www.cnblogs.com/flashicp/p/693986.html
Copyright © 2020-2023  润新知