xsharp.eu • SET DEFAULt TO <xxx> behaviour
Page 1 of 1

SET DEFAULt TO <xxx> behaviour

Posted: Thu May 06, 2021 1:22 pm
by Karl-Heinz
Guys,

it´s no final solution, i just collected what i've noticed so far ...

In the early Foxpro days there's been no CD - (C)hange (D)irectory - command. To achieve this the command 'SET DEFAULT TO <x>' was - and still is - used. The foxpro results of e.g. 'SET DEFAULT TO F:Test' are:

Code: Select all

? Set ( "Default" ) -> "F:" - same as Sys(5)   
? Curdir() -> "TEST"
It seems that Foxpro doesn't store the full path like VO does.

Code: Select all

SetDefault(F:Test)
? GetDefault() -> F:Test
In the already posted VFPSysAndDir.viaef i modified the foxpro dialect behaviour of the X# functions curDir() and curdrive(). So the X# results would be the same.

Code: Select all

? CurDrive() , Sys(5)  // "F:"  "F:"
? curdir() //  "TEST"
A modified X# SetDefault() function might look like:

Code: Select all

FUNCTION SetDefault(cPathSpec AS STRING) AS STRING
	
	SetPathArray(NULL)
	
    IF XSharp.RuntimeState.Dialect == XSharpDialect.FoxPro

		TRY 
			XSharp.IO.File.ClearErrorState()
			Directory.SetCurrentDirectory(cPathSpec) 

			cPathSpec := CurDrive()  // this would save the drive name only , e.g. "F:"
			
		CATCH e AS Exception
			XSharp.IO.File.SetErrorState(e)		
		END TRY
	
		IF RuntimeState.FileException != NULL
			THROW RuntimeState.FileException		
		ENDIF 	

    ENDIF
    
	SETSTATE STRING Set.Default  cPathSpec 
Note: Similar to the Foxpro dir commands the SET DEFAULT command throws a exception if a dir selection fails.

The question is: if the Foxpro dialect is used, what should a SetDefault("F:Test") do ? Store the given path or the drive name ?

regards
Karl-Heinz

SET DEFAULt TO <xxx> behaviour

Posted: Thu Jun 10, 2021 5:43 pm
by atlopes
Karl-Heinz, I know this is already more than a month old, but I'm reviewing the last forum threads and I have a few comments on this.

In VFP, SET("Default") returns only the drive letter, but SET DEFAULT TO x:y stores the full path.

Also, the path in the command is relative. So,

Code: Select all

SET DEFAULT TO U:Folder
SET DEFAULT TO SubFolder
is equivalent to

Code: Select all

SET DEFAULT TO U:FolderSubFolder
There is an undocumented SET DIRECTORY TO command that has the same functionality as the SET DEFAULT command, and a correspondent SET("Directory") function. The function returns the full path, contrary to SET("Default").

That is

Code: Select all

SET DEFAULT TO
SET DIRECTORY TO U:FolderSubFolder
? SET("Directory")  && displays U:FOLDERSUBFOLDER
? SET("Default")  && displays U:
? CURDIR()  && displays FOLDERSUBFOLDER