Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Extract the name of a Folder
Message
From
05/05/2009 11:07:39
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01397921
Message ID:
01397974
Views:
53
>>JUSTPATH() will extract a path w/o backslash at the end from a file name. ADDBS() will add backslash at the end of a directory name if there isn't one. However, to get correct results you have to apply JUSTPATH() to a file name and ADDBS() to a directory names respectively.
>>
>>>
>>>I have :
>>>
>>>"c:/data/data1/myfile.txt " and i want "c:/data/data1/"
>>>OR
>>>"c:/data/data1 " and i want "c:/data/data1/"
>>>OR
>>>"c:/myfile.txt " and i want "c:/"
>>>OR
>>>"c:/data/myfile.txt " and i want "c:/data/"
>>>
>>>Thanks in advance or help.
>>>
>>>bernhart

The JUSTPATH() works in the above examples except for the second case, "c:\data\data1" -- here the function will return "c:\data". The function assumes the last part to be a filename when instead this may be part of the directory path. So incorrect results may be returned in this case. You have to know before issuing the command as to whether this is only a directory path or a path with a filename. You might try:
lcPath = "c:\data\data1"
IF DIRECTORY(lcPath,1)
  lcPath = ADDBS(lcPath)
ELSE
  lcPath = ADDBS(JUSTPATH(lcPath))
ENDIF
Previous
Reply
Map
View

Click here to load this message in the networking platform