[RESOLVED] Exploring directories
I'd like to be able to depend only in the hierarchy of the directories of my project files and no in which computer, unit or server the whole project is located.
For most of the file paths I use Application.CurrentProject.Path (in this case for Access).
Suppose your file lies in directory H:\XXX\YYY\ZZZ
But in H:\XXX\ you have either:
- H:\XXX\YYY, and
- H:\XXX\RRR
Is it possible to get the current directory string, go up two directories and then just add to this string "RRR" so that you are now in H:\XXX\RRR?
This should be possible by manipulating the string and searchin character \.. but is there some other way to programm this?
Re: Exploring directories
Hi
One way I can think of is using the mid function to check for "\" and then adding the "RRR"
for example
vb Code:
Private Sub CommandButton1_Click()
Strg = "H:\XXX\YYY\ZZZ"
Count = 0
For i = 1 To Len(Strg)
If Mid(Strg, i, 1) = "\" Then
temp = Mid(Strg, 1, i - 1)
Count = Count + 1
If Count = 2 Then Exit For
End If
Next i
strg2 = temp & "\RRR"
MsgBox strg2 '<==== this will give you "H:\XXX\RRR"
End Sub
Hope this helps...
Re: Exploring directories
One way you can do this is to make an array of strings and then join them to make your new path
Dim temp(2) as string
temp(0)="H:\"
temp(1)="XXX\"
temp(2)=Name
temp(3)=".xls"
newstring=join(temp, "")
now newstring will now equal H:\XXX\Name.xls
therefore, you just change out your second value in the array, temp(2) and rejoin
Re: Exploring directories
Hi Brellis
just a thought...
how will you decide what value does temp(1) hold during runtime...
Right now we are just taking a fixed string as
Strg = "H:\XXX\YYY\ZZZ"
It will be simple to store the path in Strg during runtime in the code which I provided...
Re: Exploring directories
my bad, i thought Fonty already had the path. If he is getting the path on the fly I'd use your method, or do what I was talking about and I'd use the split command