>does the following work as well?
>
>
>mytest = lcPath + "\nul.txt"
>if file(mytest) then
> copy file (myhappyfile) to (lcPath)
>else
> md lcPath
> copy file (myhappyfile) to (lcPath)
>endif
>
>
A second problem here - in addition to the nul.txt being an invalid test, you must supply the full name of the tart file, not just a path prefix; IOW, the copy command would need to read:
COPY FILE (myhappyfile) TO (lcPath + JUSTFNAME(myhappyfile))
JUSTFNAME() is a native function for VFP 6; it requires FOXTOOLS.FLL to be loaded in earlier versions.
You need to verify that you do not have an intervening filename; if you have a file C:\FOO\BAR. and you try to MKDIR C:\FOO\BAR\MUMBLE, the MKDIR will fail, since you can't have a file and a folder with the same name. Equally, in a network environment, or under NT, where users do not automatically have write or create permissions in a directory, MKDIR may fail (eg, you want to create the subdirectory C:\FOO\BAR, but the user has only read privileges in C:\FOO).
Even under Win9x, a folder can be flagged Read-Only (an example would be some of the Windows SpecialFolders such as the FONTS directory) or System, requiring either a special API call to create files in the directories, or that you remove the attribute from the directory hefore copying to it or attempting to create a subdirectory in it.
IsWritable() detects whether you have write privileges in the designated directory; you could create a function IsCreateable() by backing up the directory tree and checking for the existance of a file or directory matching the previous layer, you can create a function that will reliably differentiate between all of the above conditions, or you can trap errors where the MKDIR fails.
Ed
>>>Hi all,
>>>
>>>The problem is simple: If I have a stored path, something like:
>>>lcPath = 'C:\thisfolderdoesnotexist\nowhere'
>>>
>>>I'd like to check if the past exists or not.
>>>
>>>I checked functions included in FOXTOOLS.FLL and nothing really did the job. I don't think VFP 6 has a function for this yet, and I'm using VFP 5 for this project. I've been suggested to use arrays, etc.
>>>
>>>But before I start jack-hammering keys like crazy, wanted to do a check first.
>>>
>>>:(
>>>
>>>What do u propose to verify for its validity?
>>>
>>
>>There are a couple of approaches you can take here. You can use ADIR() with the "D" for an attribute specifier; it works in most all cases except where there's more than one "." in one section of a folder name.
>>
>>If you need to know if a folder is writable, try to create a file using FCREATE(), and trap the error if it occurs:
>>
>>
FUNCTION IsWritable
>>LPARAMETER cDirTOCheck
>>LOCAL cErrorRtn, cTempFileName, cPathTOCheck, lSuccess, nFH
>>cPathToCheck = ALLTRIM(cDirToCheck)
>>IF RIGHT(cPathToCheck,1) # '\'
>> cpathToCheck = cpathToCheck + '\'
>>ENDIF
>>cTempFilename = SYS(3)
>>DO WHILE FILE(cPathToCheck + cTempFileName)
>> cTempFileName = SYS(3)
>>ENDDO
>>cErrorRtn = ON('ERROR')
>>lSuccess = .T.
>>ON ERROR lSuccess = .F.
>>nFH = FCREATE(cPathToCheck + cTempFileName)
>>ON ERROR &cErrorRtn
>>IF lSuccess
>> =FCLOSE(nFH)
>> ERASE (cPathToCheck + cTempFileName)
>>ENDIF
>>RETURN lSuccess