September 20, 2020, 07:38:40 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


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.

Code Select
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