Home > Software engineering >  VB how to obtain the specified file path
VB how to obtain 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:

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:

Don't quite understand what you mean,
Try this:
 Sub Main () 
Dim sPath As String
Dim sTemp As String

SPath=InputBox (" please enter the path: ",, "D: \ \ test 2")
STemp=sPath & amp; "\ instance. TXT"
If (Dir $(sTemp, 7)="") Then
MsgBox "without this file, within a specified directory", 64
The Else
MsgBox sTemp, 64
End the If
End Sub

CodePudding user response:

See you use controls open file dialog box, CommonDialog, can set the path, you retrieve attributes,

CodePudding user response:

Repeating questions, already reply

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:

When the great god send code more comments, so also convenient under the novice to learn

CodePudding user response:

1. Write the code in your application:
SPath=App. Path & amp; "\ instance. TXT"
If Dir (sPath)="" Then
MsgBox "file does not exist!"
End the If
2. The program files and put the same folder ". TXT ",
  • Related