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);
    }

  • 相关阅读:
    [BZOJ 3270] 博物馆
    [BZOJ 3551] Peaks加强版
    [HNOI 2009] 梦幻布丁
    [NOI 2018] 归程
    [YNOI 2016] 掉进兔子洞
    [SCOI 2014] 方伯伯的玉米田
    Codeforces Round #545 (Div. 2)
    初涉Min-Max容斥【在更】
    【费用流】bzoj1834: [ZJOI2010]network 网络扩容
    【最大权闭合子图】bzoj4873: [Shoi2017]寿司餐厅
  • 原文地址:https://www.cnblogs.com/flashicp/p/693986.html
Copyright © 2011-2022 走看看