zoukankan      html  css  js  c++  java
  • 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);
    }

  • 相关阅读:
    Codeforces Round #706 (Div. 2)
    Caddi Programming Contest 2021(AtCoder Beginner Contest 193)
    [ARC116] Deque Game
    Codeforces Round #721 (Div. 2)
    Codeforces Round #618 (Div. 1)
    Educational Codeforces Round 109 (Rated for Div. 2)
    [ABC201F] Insertion Sort
    AtCoder Regular Contest 119
    Codeforces Global Round 13
    Codeforces Round #673 (Div. 1)
  • 原文地址:https://www.cnblogs.com/flashicp/p/693986.html
Copyright © 2011-2022 走看看