首先讓程式檢索 程式所在檔案夾里是否有“實體.txt” 這個檔案,如果有,回傳檔案所在的完整路徑。。。。
例如:
實體.txt 這個檔案在 D:\2\test 檔案夾內,那么他的完整路徑應該為 "D:\2\test\實體.txt"
這個只是初步需要完成的。。。有沒有大神提供一下思路
uj5u.com熱心網友回復:
不太明白你的意思。試試這個:
Sub Main()
Dim sPath As String
Dim sTemp As String
sPath = InputBox("請輸入路徑:", , "D:\2\test")
sTemp = sPath & "\實體.txt"
If (Dir$(sTemp, 7) = "") Then
MsgBox "在指定目錄內沒有該檔案。", 64
Else
MsgBox sTemp, 64
End If
End Sub
uj5u.com熱心網友回復:
看你打開的檔案用控制元件對話框,CommonDialog,可以設定路徑,你獲取屬性。uj5u.com熱心網友回復:
重復提問,已回復uj5u.com熱心網友回復:
App.Path+"\"+FileName
uj5u.com熱心網友回復:
Public Declare Function GetFileAttributesW Lib "KERNEL32.dll" (ByVal lpFileName As Long) As Long
Public Const INVALID_HANDLE_VALUE = -1&
Public Enum enumFileNameParts
efpFileName = 2 ^ 0
efpFileExt = 2 ^ 1
efpFilePath = 2 ^ 2
efpFileNameAndExt = efpFileName + efpFileExt
efpFileNameAndPath = efpFilePath + efpFileName
End Enum
Public Function DoesFileExist(FileName As String) As Boolean
' test to see if a file exists
DoesFileExist = Not (GetFileAttributesW(StrPtr(FileName)) = INVALID_HANDLE_VALUE)
End Function
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
' GetFileName
' This function is used to parse keys peices of info from a
' filename that is passed into it.
Public Function GetFileName(ByVal sFile As String, ByVal ePortions As enumFileNameParts) As String
Dim lFirstPeriod As Long
Dim lFirstBackSlash As Long
Dim sRet As String
Dim sPath As String
Dim sName As String
Dim sExt As String
lFirstPeriod = InStrRev(sFile, ".")
lFirstBackSlash = InStrRev(sFile, "\")
If lFirstBackSlash > 0 Then
sPath = VBA.Left$(sFile, lFirstBackSlash)
End If
If lFirstPeriod > 0 And lFirstPeriod > lFirstBackSlash Then
sExt = Mid(sFile, lFirstPeriod + 1)
sName = Mid(sFile, lFirstBackSlash + 1, lFirstPeriod - lFirstBackSlash - 1)
Else
sName = Mid(sFile, lFirstBackSlash + 1)
End If
If ePortions And efpFilePath Then
sRet = sRet & sPath
End If
If ePortions And efpFileName Then
sRet = sRet & sName
End If
If ePortions And efpFileExt Then
If sRet <> "" Then
sRet = sRet & "." & sExt
Else
sRet = sRet & sExt
End If
End If
GetFileName = sRet
End Function
uj5u.com熱心網友回復:
大神們發代碼的時候多點注釋,這樣也方便菜鳥學習下uj5u.com熱心網友回復:
1.在程式中寫代碼:sPath = App.Path & "\實體.txt"
If Dir(sPath) = "" Then
MsgBox "檔案不存在!"
End If
2.將程式檔案和”實體.txt”放同一檔案夾中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/85546.html
標籤:VB基礎類
上一篇:用VB 解壓帶密碼的rar檔案
下一篇:VB 指定檔案的路徑獲取
