I want to create a file but 1 directory above app.path.
app.path & ???? & "\test1.txt"
in unix it would be \.. to go to the above directory
what does ???? need to be to achieve this
Printable View
I want to create a file but 1 directory above app.path.
app.path & ???? & "\test1.txt"
in unix it would be \.. to go to the above directory
what does ???? need to be to achieve this
You could read the current path and strip out everything after the second \ from the right and then use the remaining path as your string.
VB Code:
Dim i As Integer i = InStrRev(App.Path, "\") MsgBox Left$(App.Path, i)
vbuser1
Or
app.path & "\..\test1.txt"
All that does is add \..\test1.txt to the current path, not bring it up a level.
OK, then it is
app.path & "\..\..\test1.txt"
All you are doing is adding the string to app.path, it wont use the \.. command like you can at the command prompt, which is really cd.. for Windows.
Why dont you get App.Path and then remove the name of the folder the application is in ?!
BrianS,
You are incorect. I use relative paths all the time to get to files. The OS understands this and it does work.
Randem's method works. And it's
to get the parent directory.VB Code:
App.Path & "\.."
Leecher
Then please explain what I'm doing wrong to try his example:
VB Code:
Option Explicit Dim path As String Private Sub Form_Load() MsgBox App.path path = App.path & "\.." End Sub
? app.Path
C:\Program Files\Microsoft Visual Studio\VB98
? path
C:\Program Files\Microsoft Visual Studio\VB98\..
The string will read "C:\1\2\3\.."
But if you try to create "Test.txt" in "C:\1\2\3\.." it will actually create "C:\1\2\Test.txt".
Leecher
I have to agree with Brian in this case... I get the same results :confused:Quote:
Originally posted by BrianS
Then please explain what I'm doing wrong to try his example:
VB Code:
Option Explicit Dim path As String Private Sub Form_Load() MsgBox App.path path = App.path & "\.." End Sub
? app.Path
C:\Program Files\Microsoft Visual Studio\VB98
? path
C:\Program Files\Microsoft Visual Studio\VB98\..
manavo11
You should... You have to create the file or open it. It is not in human format, the OS understands it thought. Use it like this:
App.Path & "\..\Test.txt"
So you're right :eek: :p
I did :
VB Code:
Private Sub Form_Load() Dim FF As Integer FF = FreeFile Open App.Path & "\..\Test.txt" For Output As #FF Close #FF End Sub
and it worked ;)
app.path & "\..\test1.txt"
does work when creating a file but the path when display to the screen doesn't match. Thank you all.