-
July 19th, 2002, 04:26 PM
#1
App.Path issue
What is the difference if I execute App.Path & "\File.txt" or just "File.txt". I mean what's the use of App.Path anyway if the default path is App.Path when working with files?
-
July 19th, 2002, 04:47 PM
#2
"App.Path" is an insurance that you're referrring to your application's path for files. I have observed in the past that when I frequently use ChDir in my applications, the "defaut" path can "go wild."
Sorry, it was just an observation which I did not verify very well because "App.Path" can easily put me back in the right track.
Marketing our skills - please participate in the survey and share your insights
-
-
July 19th, 2002, 04:58 PM
#3
'Add to a form a Commondialog box and a commandbutton. Compile project and make an executable.
'Add a file called Myfile.txt to the folder with the just created executable.
Code:
Option Explicit
'In principal if the current directory, which is by default is the same as the app.path, did not
'change through the whole application then you don't need the app.path. But if the current directory changes then
'you start getting problems. Below there are two cases where the current directory changes and you get the wrong path.
Private Sub Command1_Click()
'By default the current directory is the app.path
MsgBox "File:" & Dir("Myfile.txt") & " Current dir: " & CurDir
'If you select a file from another directory the you changed the current directory
'So in principal Myfile.txt Dir("Myfile.txt") should be empty
CommonDialog1.ShowOpen
MsgBox "File:" & Dir("Myfile.txt") & " Current dir: " & CurDir
'Similarly if you change the current directory using ChDir then
'Dir("Myfile.txt") will probably be empty
ChDir "c:\"
MsgBox "File:" & Dir("Myfile.txt") & " Current dir: " & CurDir
End Sub
-
July 19th, 2002, 05:24 PM
#4
With Flags property you can control behavior of CommonDialog
That code does not change programs CurDir
CommonDialog1.Flags = CommonDialog1.Flags Xor cdlOFNNoChangeDir
That code change programs CurDir
CommonDialog1.Flags = CommonDialog1.Flags or cdlOFNNoChangeDir
-
July 19th, 2002, 05:41 PM
#5
Sometimes, the App.path is different from the path where the environment runs it ( Check shortcut for example ).
The app.path refers to where the EXE file is. but it could run in another directory. So if you just specify text.txt it checks on the current working directory which might be different from where the applications resides.
Nicolas Bohemier
-
July 20th, 2002, 04:32 PM
#6
Hi,
so pretty much App.Path is required? How come when App.Path is c:\ or c:\folder it still work using App.Path & "\file.txt"??? I mean if App.Path is c:\ then App.Path & "\file.txt" would be c:\\file.txt. I tried both and it still works. Do i have to create a control code something like
Code:
If Right(App.Path, 1) = "\" Then
ProgPath = Left(App.Path, Len(App.Path) - 1)
Else: ProgPath = App.Path
End If
to make sure it works or it'll work anyway?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|