• 两种方式获取临时文件


    两种方式获取临时文件

    Path.GetTempPath 方法 [C#]请參见
    Path 类 | Path 成员 | System.IO 命名空间 
    要求
    平台: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family

    .NET 框架安全性:

    EnvironmentPermission 用于对环境变量的无限制訪问。关联的枚举:PermissionState.Unrestricted 
    语言
    C#

    C++

    JScript

    Visual Basic

    所有显示


    返回当前系统的暂时目录的路径。

    [Visual Basic]
    Public Shared Function GetTempPath() As String
    [C#]
    public static string GetTempPath();
    [C++]
    public: static String* GetTempPath();
    [JScript]
    public static function GetTempPath() : String;
    返回值
    包括暂时文件夹的路径信息的 String。

    异常
    异常类型 条件 
    SecurityException 调用方没有所需的权限。

    备注
    以下的代码演示样例说明 GetTempPath 方法的使用方法。

    [Visual Basic] 
    Dim tempPath As String = Path.GetTempPath()
    Console.WriteLine("Temporary pathname is '{0}'", tempPath)

    Dim tempDir As New DirectoryInfo(tempPath)
    Console.WriteLine("{0} contains {1} files", tempPath, tempDir.GetFiles().Length)
    [C#] 
    string tempPath = Path.GetTempPath();
    Console.WriteLine("Temporary path is '{0}'", tempPath);

    DirectoryInfo tempDir = new DirectoryInfo(tempPath);
    Console.WriteLine("{0} contains {1} files", tempPath, 
    tempDir.GetFiles().Length);

    当然,还有个GETTEMPFILENAME能够看看
    ----------------------------------------------------------

    第二种似乎仅仅能用API了吧

    [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
    [return:MarshalAs(UnmanagedType.U4)]
    public static extern int GetTempFileName(
    string strPathName,
    string strPrefixString,
    [MarshalAs(UnmanagedType.U4)] uUnique,
    StringBuilder sbTempFileName);

  • 相关阅读:
    ssh.sh_for_ubuntu1604
    ssh.sh_for_ubuntu1404
    ssh.sh_for_ubuntu1204
    ssh.sh_for_centos
    raw,cow,qcow,qcow2镜像的比较
    Oz 创建Windows2008R2镜像
    Oz 创建Ubuntu镜像
    Oz 创建Debian8镜像
    Oz 创建CentOS7镜像
    Oz 创建CentOS6镜像
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5049538.html
Copyright © 2020-2023  润新知