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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CD (SaveDir) doesn't work in Windows 7?

Status
Not open for further replies.

mkrausnick

Programmer
Apr 2, 2002
766
0
0
US
I finally broke down and installed VFP on my Win7 machine. Cruising along fine, and then this completely unexpected error happens:
This code:

Code:
SaveDir=curdir()
CD <some_other_folder_on_the_same_drive>
.
. some code
.
CD (SaveDir)

yields "Invalid path or file name."

I've used this construct for years in WinXP with no problem.

Has anyone else come across this, and is there a workaround?

Mike Krausnick
Dublin, California
 
Works for me, eeg in the form of

Code:
SaveDir=curdir()
CD ..
*
CD (SaveDir)

also variants instead of CD .. like CD \Windows and others work. I was unable to make this fail.

Make sure the "some code" section does neither change the SaveDir variable value nor changes to a different drive, eg via calling some class, method, function which itself uses some other code and that changes drive.

That's the disadvantage of the curdir() result, not having the drive letter in it. Instead of curdir() using fullpath(curdir()) or Sys(5)+Sys(2003) would also work independent of a drive change.

For analysis check out Sys(5)+Sys(2003) and the SaveDir value before doing CD (SaveDir), check if DIRECTORY(Sys(5)+SaveDir) exists.

I always am an evangelist for absolute paths for such scenarios, not absolute in the sense of being hardcoded, unchangable, unconfigurable, but the absolute path determined at runtime from a current or relative path. Fullpath() is a function to remember for that matter to merge an absolute and relative path to the resulting fullpath, determined that at runtime, SYS(2014) is another function to keep in mind. A relative path expanded to a full path at runtime will undoubtedly work, unless "some code" deletes a folder, but regardless to where other code changes the current dir. The drive letter is an info missing from curdir(), and that's therefore insufficient, no matter how often, long or loud you swear no other code changes drive.

Also I see a tendency here, that is really making me sad. Both users and developers argue with "this will never happen". You always have to expect the unexpected. In development you normally are not alone, even as a single freelance developer you make use of libraries written by other developers, you work in a multiprocessing operating system etc. The argument of "this has worked in system X for N years, never failed" also is a very moot point.

Changing OS and something stops working, I can understand you first suspect an OS bug or behavior change, but that's not the case here. Double check the circumstances of an error. SAVE TO some.mem ALL LIKE * will make your error handler save all variables, if you also store sys(5)+Sys(2003) you can see why CD (SaveDir) errors. And undoubtedly, if that error comes up, either SaveDir has changed, the current drive has change, the folder was deleted or renamed or the folder is hidden or granted privileges have changed. There are very many reasons and they all don't only depend on your code, other programs can do things in parallel, for example. Get real.

Bye, Olaf.
 
I concur with Olaf: use FULLPATH() and check if DIRECTORY(m.SaveDir) == True before issuing CHDIR (I prefer it to CD).
(If it's of any consolation: I've had my (un-)fair ;-) share of troubles with CURDIR() back in the VFP3 days... and was glad when I discovered FULLPATH() in later versions!)
Just FYI: issuing FULLPATH("") returns the path (as String) with terminating backslash, FULLPATH(".") - without that backslash.
HTH.

Regards,

Ilya
 
Are you on the same drive or the same mapped drive? CURDIR() only returns the path, not the drive if mapped.
 
I did not know about 'fullpath(".")' Ilya. Always used 'JustPath(fullpath([]))'.
Thanks!

-Stephen
 
Look it up at the VPF's Help. OR - here it goes:

Returns the path to a specified file or the path relative to another file.

FULLPATH(cFileName1 [, nMSDOSPath | cFileName2])

Parameters

cFileName1

Specifies the file for which Visual FoxPro searches. If the file is located in the Visual FoxPro path, the path is returned with the file name. You can specify the Visual FoxPro path using the SET PATH command. If the file cannot be located in the Visual FoxPro path, FULLPATH( ) returns the current directory the path and file name as if the file was located in the current default directory.

nMSDOSPath

Specifies to search the MS-DOS path instead of the Visual FoxPro path. nMSDOSPath can have any numeric value. If the file cannot be located in the MS-DOS path, FULLPATH( ) returns the path and the file name as if the file was located in the current default directory.

cFileName2

Specifies a second file name to search for. FULLPATH( ) returns the path for the first file relative to the second file.

Return Value

Character. FULLPATH( ) returns a file path.

Remarks
Use the FILE( ) function to verify that the file actually exists; otherwise, if the file does not exist, the function returns the file name with the current directory.
HTH.


Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top