Home > Software engineering >  VB of the specified file path
VB of the specified file path

Time:09-27

First let the program to retrieve the folder ". TXT "this file, if any, returns the full path to the location of the file,,,,

For example:
Reference
instance. TXT this file in D: \ \ test 2 folder, so his full path should be "D: \ \ test \ 2 instances. TXT"




This is just a preliminary needs to be done, and, have a great god provides a train of thought

CodePudding user response:

Dir () function

CodePudding user response:

How to obtain various subdirectories under the file name (including the full path)
 Dim colFiles As Collection 
Dim As Long I
The Set colFiles=SearchFiles (" D: \ ", "instances. TXT")
For I=1 To colFiles. Count
The Debug. Print colFiles (I)
Next

CodePudding user response:

 App. The Path + "" + FileName 

CodePudding user response:

 
Public Declare Function GetFileAttributesW Lib "KERNEL32. DLL" (ByVal lpFileName As Long) As Long
Public Const INVALID_HANDLE_VALUE=https://bbs.csdn.net/topics/-1&
Public Enum enumFileNameParts
EfpFileName=2 ^ 0
EfpFileExt=2 ^ 1
EfpFilePath=2 ^ 2
EfpFileNameAndExt=efpFileName + efpFileExt
EfpFileNameAndPath=efpFilePath + efpFileName
End Enum
The Public Function DoesFileExist (FileName As String) As Boolean

'the test to see if a file exists

DoesFileExist=Not (GetFileAttributesW (StrPtr (FileName))=INVALID_HANDLE_VALUE)

End the Function

'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'the GetFileName
'This function is 2 parse keys peices of info from a
'filename that is passed into it.

The 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 & gt; 0 Then
SPath=VBA. Left $(sFile lFirstBackSlash)
End the If
If lFirstPeriod & gt; 0 And lFirstPeriod & gt; LFirstBackSlash Then
SExt=Mid (sFile, lFirstPeriod + 1)
SName=Mid (sFile lFirstBackSlash + 1, lFirstPeriod lFirstBackSlash - 1)
The Else
SName=Mid (sFile, lFirstBackSlash + 1)
End the If
If ePortions And efpFilePath Then
SRet=sRet & amp; SPath
End the If
If ePortions And efpFileName Then
SRet=sRet & amp; SName
End the If
If ePortions And efpFileExt Then
If sRet & lt;> "" Then
SRet=sRet & amp; ". "& amp; SExt
The Else
SRet=sRet & amp; SExt
End the If
End the If
GetFileName=sRet

End the Function


CodePudding user response:

If dir (App. Path & amp; "\ instance. TXT") & lt;>" "Then
Msgbox App. Path + "\ instance. TXT"
endif
  • Related