Disk functions

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Disk functions

Post by Karl-Heinz »

Hi Chris & Robert

VFP has also a - slightly different working - DiskSpace() function. How should it be implemented ? I'm thinking about to enhance the current XSharp.core code. The currently available overloads are

Code: Select all

FUNCTION DiskSpace() AS INT64 
FUNCTION DiskSpace(nDrive AS INT) AS INT64
FUNCTION DiskSpace(cDrive AS STRING) AS INT64 
the required VFP overloads are

Code: Select all

FUNCTION DiskSpace() AS INT64 
FUNCTION DiskSpace( cDrive AS STRING ) AS INT64 
FUNCTION DiskSpace( cDrive AS STRING , nType AS INT ) AS INT64 
My idea is to do the main work inside the new DiskSpace( cDrive AS STRING , nType AS INT ) overload. The required changes would be:

Code: Select all

FUNCTION DiskSpace() AS INT64 

	// replacement for the existing core code 
	
	IF Runtimestate.Dialect == XSharpDialect.FoxPro
		RETURN DiskSpace ( CurDrive(), 2 )   // 2 is the VFP <nType> default 
	ELSE 
		RETURN DiskSpace ( CurDrive(), 1 )   // VO returns always oDrive:TotalSize  		
	ENDIF 

FUNCTION DiskSpace(cDrive AS STRING) AS INT64

	// replacement for the existing core code 
	
	IF Runtimestate.Dialect == XSharpDialect.FoxPro
		RETURN DiskSpace ( cDrive , 2 )   // 2 is the VFP <nType> default 
	ELSE 
		RETURN DiskSpace ( cDrive , 1 )   // VO returns always oDrive:TotalSize  		
	ENDIF 


FUNCTION DiskSpace(nDrive AS INT) AS INT64
	LOCAL cDisk AS STRING
	cDisk := DiskNo2DiskName(nDrive)
	RETURN DiskSpace(cDisk, 1 ) <---- // VO returns always oDrive:TotalSize 

:
the additional overload looks like:

Code: Select all

FUNCTION DiskSpace( cDrive AS STRING , nType AS INT ) AS INT64 
LOCAL result AS INT64 


	IF String.IsNullOrEmpty(cDrive) 
		cDrive := CurDrive() 
	ELSEIF cDrive:Length > 1 
		cDrive := cDrive:Substring(0,1)+":"
	ENDIF 


	// todo: verify the nType param 

	
	TRY 
		
		// XSharp.IO.File.ClearErrorState()		
		
		VAR oDrive := System.IO.DriveInfo{cDrive}


		// todo: verify the results   
				
		SWITCH nType
			
		CASE 1
			result := oDrive:TotalSize  
		CASE 2  
			result := oDrive:TotalFreeSpace  
		CASE 3				
			result := oDrive:AvailableFreeSpace  
			
		END SWITCH 
	
		
	CATCH e AS Exception 
		
		// XSharp.IO.File.SetErrorState(e)

		IF Runtimestate.Dialect == XSharpDialect.FoxPro		
			result := -1		
		ELSE 
			result := 0		
		ENDIF 			
		
	END TRY 			
	
	RETURN result
What do you think ?

regards
Karl-Heinz
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Disk functions

Post by robert »

Karl-Heinz,
This looks like a good approach. I must admit that I have not looked at the Vfp Implementation but this should work.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Disk functions

Post by Karl-Heinz »

some questions to the VFP community

if a dir command fails, does VFP always throw an runtime error ?

MD D:Test2Test
MKDIR D:Test2Test

error because dir already exists, drive is unknown. etc.


RD D:Test2Test
RMDIR D:Test2Test

error because dir is not empty, dir doesn't exist, etc.


CD D:Test2test
CHDIR D:Test2test

error because dir doesn't exist, etc.


[Edit start - i modified the ".." and "" description ]

Select a parent dir:

X#/VO uses DirChange ( ".." )

CD ..
CHDIR ..

select the root dir

X#/VO uses DirChange ( "" )

CD
CHDIR

[Edit end]


Another question: let´s say there's an empty dir tree

d:Test2Test

can you delete the complete tree with one call

RD D:Test2Test

or step by step only ?

RD D:Test2Test
RD D:Test2


regards
Karl-Heinz
User avatar
Сергей
Posts: 4
Joined: Fri Feb 26, 2021 11:17 am

Disk functions

Post by Сергей »

Karl-Heinz wrote:some questions to the VFP community

if a dir command fails, does VFP always throw an runtime error ?

MD D:Test2Test
MKDIR D:Test2Test

error because dir already exists, drive is unknown. etc.
Yes.


RD D:Test2Test
RMDIR D:Test2Test

error because dir is not empty, dir doesn't exist, etc.
Yes.


CD D:Test2test
CHDIR D:Test2test

error because dir doesn't exist, etc.
Yes.

Another question: let´s say there's an empty dir tree

d:Test2Test

can you delete the complete tree with one call

RD D:Test2Test

or step by step only ?
Complete tree. If it empty.
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Disk functions

Post by Karl-Heinz »

Thanks for the input !

Here are some more differences that I have found so far.

1. Sys(5) is similar to the X#/VO CurDrive()
while Sys(5) returns e.g. "D:", the X#/VO CurDrive() returns "D"

2. Both know the CurDir() function.
while Fox returns e.g. "TEST , the X#/VO CurDir() returns "TEst"

But the main difference seems to be the SET DEFAULT TO behaviour. Because the Fox SET DEFAULT TO changes the current directory, the sys (5) and CurDir() content depend on this setting. I think VFP still works the same way ?

Here's the Foxpro code i'm using.

Code: Select all

clear
set talk off


cStartDir = Set ("default") + CurDir()
? cStartDir

? Set ("default")					&& "D:"
? CurDir()							&& ""
? sys(5)							&& "D:"
? FullPath ( Set ("default" ) )		&& "D:"
? sys(5) + CurDir()					&& "D:"
?
set default TO d:test
? Set ( "default" )					&& "D:"
? CurDir()							&& "TEST"
? sys(5)							&& "D:"
? FullPath ( Set ("default" ) )		&& "D:TEST"
? sys(5) + CurDir()					&& "D:TEST"

?
set default TO f:xide
? Set ( "default" )					&& "F:"
? CurDir()							&& "XIDE"
? sys(5)							&& "F:"
? FullPath ( Set ("default" ) )		&& "F:XIDE"
? sys(5) + CurDir()					&& "F:XIDE"

?
Set default TO (cStartDir)
? Set ( "Default" )					&& "D:"
? CurDir()							&& ""
? sys(5)							&& "D:"
? FullPath ( Set ("default" ) )		&& "D:"
? sys(5) + CurDir()					&& "D:"
and here's some code that shows how X#/VO works.

Code: Select all

FUNCTION Start( ) AS VOID 

	? GetDefault()  // C:XIDEProjectsProject1BinDebug
	? CurDrive()	// C
	? CurDir()	// XIDEProjectsProject1BinDebug 
	?
	DirChange ( "D:TEst" )
    	?
	? GetDefault()	// C:XIDEProjectsProject1BinDebug // <--  still the same	
	? CurDrive()	// D
	? CurDir()	// TEst     
	?
	SetDefault ( "C:windows")
	? GetDefault()	// C:windows
	? CurDrive()	// D  	<--  still the same  
	? CurDir()	// TEst	<--  still the same   
Because my old Foxpro doesn't know dir commands like CHDIR: If a directory is changed, what is afterwards the content of Sys(5), CurDir() and Set("Default") ?

regards
Karl-Heinz
User avatar
Сергей
Posts: 4
Joined: Fri Feb 26, 2021 11:17 am

Disk functions

Post by Сергей »

Karl-Heinz wrote:Because my old Foxpro doesn't know dir commands like CHDIR: If a directory is changed, what is afterwards the content of Sys(5), CurDir() and Set("Default") ?
Same as Set default.
Post Reply