如何获取系统的临时目录路径?
GetTempPath取得的是一個(gè)DOS名稱,當(dāng)文件名長(zhǎng)度大于8時(shí),長(zhǎng)文件名格式“C:/Documents and Settings/Administrator/Local Settings/Temp”會(huì)顯示成“C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp”的短文件名格式,如何根據(jù)自己需要取得系統(tǒng)臨時(shí)目錄的途徑,下面是一個(gè)新寫的函數(shù),調(diào)用兩個(gè)API 實(shí)現(xiàn),相信許多朋友可能用得到。
Option Explicit
Private Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Sub GetTEMPfolder(Optional ByVal showlong As Boolean = True)
???
??? Dim longname As String, shortname As String
???
??? shortname = Space(256)
??? GetTempPath Len(shortname), shortname
?
??? longname = Space(1024)
??? GetLongPathName shortname, longname, Len(longname)
?
???? MsgBox "Tempfolder : " & IIf(showlong = True, longname, shortname)
?
?End Sub
Private Sub Command1_Click()
?GetTEMPfolder '長(zhǎng)文件名
?GetTEMPfolder False '短文件名
End Sub
轉(zhuǎn)載于:https://www.cnblogs.com/fengju/archive/2004/07/30/6336383.html
總結(jié)
以上是生活随笔為你收集整理的如何获取系统的临时目录路径?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Spring.Net对Web页面进行
- 下一篇: java 历届试题 合根植物