首先讓程式檢索 程式所在檔案夾里是否有“實體.txt” 這個檔案,如果有,回傳檔案所在的完整路徑。。。。
例如:
這個只是初步需要完成的。。。有沒有大神提供一下思路
uj5u.com熱心網友回復:
dir()函式uj5u.com熱心網友回復:
怎樣取得各級子目錄下的檔案名(包含全路徑)Dim colFiles As Collection
Dim i As Long
Set colFiles = SearchFiles("D:\","實體.txt")
For i = 1 To colFiles.Count
Debug.Print colFiles(i)
Next
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熱心網友回復:
if dir(App.Path & "\實體.txt")<>"" thenmsgbox App.Path+"\實體.txt"
endif
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/85547.html
標籤:VB基礎類
上一篇:VB 如何獲得指定檔案路徑
