-
1
- #1
App.Path returns the folder that the application is installed to, so App.Path & "\test.txt" should return the path and file name of a file with the name test.txt in the folder that your application is installed to.
Unfortunately, this will give errors under certain circumstances.
If for some reason, your user decides to install your application directly onto the root of a drive (c drive for example) App.Path & "\test.txt" will produce an error.
The reason for this is that App.Path returns the path of a folder name that the application is installed to, without a backslash if the application is installed to a folder on a drive, but returns the drive name colon backslash if your application is installed directly onto a drive.
I.E. if your application is installed to c:\program files\your_app_name, App.Path will return
C:\Program files\your_app_name
But if your application is installed directly onto the c drive, App.Path will return
C:\
In this instance, appending "\test.txt" will result in the string
"C:\\test.txt"
giving errors.
For this reason, I code a function called App_Path which is as follows:
Pulbic Function App_Path() As String
If Right(App.Path, 1) = "\" Then
App_Path = App.Path
Else
App_Path = App.Path & "\"
End If
End Function
and the I use App_Path & filename.extension to avoid these errors.
Simon
Unfortunately, this will give errors under certain circumstances.
If for some reason, your user decides to install your application directly onto the root of a drive (c drive for example) App.Path & "\test.txt" will produce an error.
The reason for this is that App.Path returns the path of a folder name that the application is installed to, without a backslash if the application is installed to a folder on a drive, but returns the drive name colon backslash if your application is installed directly onto a drive.
I.E. if your application is installed to c:\program files\your_app_name, App.Path will return
C:\Program files\your_app_name
But if your application is installed directly onto the c drive, App.Path will return
C:\
In this instance, appending "\test.txt" will result in the string
"C:\\test.txt"
giving errors.
For this reason, I code a function called App_Path which is as follows:
Pulbic Function App_Path() As String
If Right(App.Path, 1) = "\" Then
App_Path = App.Path
Else
App_Path = App.Path & "\"
End If
End Function
and the I use App_Path & filename.extension to avoid these errors.
Simon