| Subject |
Re: path test |
| From |
Gaetano D. <gaetanodd@hotmail.com> |
| Date |
Fri, 23 Apr 2021 10:10:14 +1000 |
| Newsgroups |
dbase.getting-started |
On 23/04/2021 7:44, Charlie wrote:
> Thanks Mervyn...
>
> One other question... if using fileex you find out the directory doesn't exist and you would like to make the directory.. You would have to md C:\dbase first then md c:\dbase\test. This would be easy doing it manually, but say you wanted to program this separating the string somehow before the second "\" So somehow c:\dbase would be made then c:\dbase\test would be made. Would fileex help with this or is there some other way you could do it? Hope I explained this correctly.
>
> Thanks
>
> Mervyn Bick Wrote:
>
>> On 2021/04/22 11:18, Charlie wrote:
>>> Is there a way of testing to see if a path exists? Only the path which may be empty.
>>>
>>> Check to see if 'c:\dbase\test' not 'c:\dbase\test\something.prg'
>> set procedure to :duflp:fileex.cc
>> fx = new fileex()
>>
>>
>> ? if fx.isdir('c:\dbase\test')
>>
>> Mervyn.
>>
>>
>>
Try this:
set procedure to :duflp:fileex.cc
set procedure to :duflp:stringEx.cc
fx = new fileex()
st=new stringex()
//adding a trailing "\" to facilitate the loop
cDir='c:\dbase\test1\test2\'
//if the dir does not exist, start from the lowest level one and loop to
test
// whether each successive level exists
if not fx.isdir(cDir)
//count dirs in the path
nDirs = st.atcount("\",cDir)
n=0
//starting at 2 because the first one is the root dir, and the
first directory
//ends at the 2nd backslash
For i=2 to nDirs
tempDir=cDir.substring(0,at("\",cDir,i)-1)
//if it doesn't exist, create it
if not fx.isdir(tempDir)
mkdir &tempDir
endif
n++ //increment level counter
endfor // next level down
endif// if the dir exists, there's nothing to create
release object fx
release object st
close proc :duflp:fileex.cc
close proc :duflp:stringEx.cc
HTH
Gaetano.
|
|