Hi,
Here is a useful little tool I have just written.
It takes a string that contains a file path, here is an example....
C:\\test\\SubTest\\Project\\Bin
Now I have some programs that work in the Bin folder, and the main program works in the folder which is one up from Bin, that is the Project folder.
I needed a simple way to get a program in the Bin folder to run the main program in the Project folder, so I wrote this code to move up a level.
It returns the path of the level up from what you specify, you can specify the number of levels to move up as well.
Example usage:
1. SYSTEM MoveUpAlevel(getstartpath,1) + "convertkeywords.exe"
Here i'm running this from the C:\\test\\SubTest\\Project\\Bin folder, but want to run convertkeywords.exe in the Project folder (one level up).
2. x$ = MoveUpAlevel(MyPath,2)
Where x$ will have the path two folders up from MyPath (whatever that may be).
Specify too many levels to move up and it returns "Too many levels up".
Think it's a useful tool.
Try it in a sub folder.
string spin = getstartpath
string UpAlevel
int a,b
int posat,levels
openconsole
print
print MoveUpAlevel(spin,1)
print
do:until inkey$ <> ""
closeconsole
end
sub MoveUpAlevel(string PathIn,int Up),string
spin = PathIn
for a = 1 to len(spin)
string chin = mid$(spin,a,1)
if chin = "\\"
levels = levels + 1
endif
next a
Levels = levels - 1
if Up > Levels then return "Too many levels up"
for b = 1 to Up
spin = mid$(spin,1,len(spin)-1)
for a = 1 to len(spin)
chin = mid$(spin,a,1)
if chin = "\\"
posat = a
endif
next a
UpAlevel = mid$(spin,1,posat)
spin = UpAlevel
next b
return spin
endsub
Andy.
:)
Now all you need is a WSTRING version ;D
In the good old DOS days, you just typed "cd.." to move back a level. Still works in Windows, as well
Brian