Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Anyone know of a way to check for valid path?
Message
From
27/02/1999 15:30:25
 
 
To
27/02/1999 14:43:41
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00192165
Message ID:
00192376
Views:
17
>does the following work as well?
>
>
>mytest = lcPath + "\nul.txt"      && nul.txt should exist in every directory!
>if file(mytest) then && dir exists
>    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
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform