Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding root of a folder 1

Status
Not open for further replies.

button71

Programmer
Nov 8, 2006
69
AU
Is there a function around to find the root of a folder?

I am using a folder Aviation

It has a path - say C:\My Pictures\Aviation

I want to get to C:\My Pictures\

Anybody help?

Willaim
 
cPath="C:\My Pictures\Aviation"
?GETWORDNUM(cPath,1,"\")+"\"+GETWORDNUM(cPath,2,"\")+"\"
 
Geoff,

But surely that only works if the file is one-level down from the root?

If you do:

JUSTPATH("c:\my pictures\my aviation pictures\aviation")

then you'll get "c:\my pictures\my aviation pictures". That's not what William wanted, as far as I can see.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Code:
CLEAR
m1 = "c:\my pictures\my aviation pictures\aviation"
? LEFT(m1,AT([\],ADDBS(m1),2))
m1 = "c:\my pictures\my aviation pictures"
? LEFT(m1,AT([\],ADDBS(m1),2))
m1 = "c:\my pictures"
? LEFT(m1,AT([\],ADDBS(m1),2))

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
You can use following code:

lcOrigDir=sys(5)+sys(2003)
lcCurDir=curDir()
lcRootDir=lcCurDir
DO WHILE .not.(lcCurDir == "\")
lcRootDir=lcCurDir
cd ..
lcCurDir=curDir()
ENDDO
set default to (lcOrigDir)
? lcRootDir
 
Sorry about the 'sleep' delay in answering we're 9.5 hrs in front of GMT down here <G>

To clarify I should have used a longer path - I need the folder above the one used before.

The start path will be of unknown length so the number of iterations is variable.

In my own clumsy way I coded

Code:
FUNCTION folderbefore
PARAMETERS  mytarget


*!*			mytarget is the previously used path

a = substr(mytarget ,len(mytarget),1)
IF a='\'
	N = 0
ELSE
	N = 1
ENDIF
Start = 1
DO while start # 0
	Start = rat('\',mytarget )
	mytarget = subst(mytarget,1,start - 1)
	IF n = 1
		mypictarget = mytarget
		EXIT
	ENDIF
	N = n+1
	
*!*		new path = mypictarget 
ENDDO
? mypictarget

RETURN mypictarget

The idea is that as the app is about viewing pictures after looking at one folder the user can choose to look at another below that parent folder.

Thanks

William
 
Dan,

Many thanks - simplicity itself!

I just needed to

Code:
set defa to the original path

first - then bingo.

Great!

William
 
Thanks, Jan, but I learned it from Dave Frankenbach. Next time you see him, buy him a beer. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top