March 28, 2024, 07:34:18 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Start path level up

Started by Andy, December 31, 2019, 12:19:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

December 31, 2019, 12:19:34 AM Last Edit: December 31, 2019, 03:07:31 AM by Andy
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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Now all you need is a WSTRING version  ;D
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

In the good old DOS days, you just typed "cd.." to move back a level. Still works in Windows, as well

Brian