Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

Disk functions 17 Apr 2021 11:35 #18049

  • Karl-Heinz
  • Karl-Heinz's Avatar
  • Topic Author


  • Posts: 774
  • 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
    FUNCTION DiskSpace() AS INT64 
    FUNCTION DiskSpace(nDrive AS INT) AS INT64
    FUNCTION DiskSpace(cDrive AS STRING) AS INT64 
    the required VFP overloads are
    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:
    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:
    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

    Please Log in or Create an account to join the conversation.

    Last edit: by Karl-Heinz.

    Disk functions 17 Apr 2021 12:18 #18050

    • robert
    • robert's Avatar


  • Posts: 3446
  • 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

    Please Log in or Create an account to join the conversation.

    Disk functions 24 Apr 2021 13:27 #18144

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • some questions to the VFP community

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

    MD D:\Test2\Test
    MKDIR D:\Test2\Test

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


    RD D:\Test2\Test
    RMDIR D:\Test2\Test

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


    CD D:\Test2\test
    CHDIR D:\Test2\test

    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:\Test2\Test

    can you delete the complete tree with one call

    RD D:\Test2\Test

    or step by step only ?

    RD D:\Test2\Test
    RD D:\Test2


    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    Last edit: by Karl-Heinz.

    Disk functions 24 Apr 2021 18:26 #18153

    • Сергей
    • Сергей's Avatar


  • Posts: 4
  • Karl-Heinz wrote: some questions to the VFP community

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

    MD D:\Test2\Test
    MKDIR D:\Test2\Test

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

    Yes.



    RD D:\Test2\Test
    RMDIR D:\Test2\Test

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

    Yes.



    CD D:\Test2\test
    CHDIR D:\Test2\test

    error because dir doesn't exist, etc.

    Yes.


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

    d:\Test2\Test

    can you delete the complete tree with one call

    RD D:\Test2\Test

    or step by step only ?

    Complete tree. If it empty.

    Please Log in or Create an account to join the conversation.

    Disk functions 24 Apr 2021 19:14 #18154

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • 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.
    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.
    FUNCTION Start( ) AS VOID 
    
    	? GetDefault()  // C:\XIDE\Projects\Project1\Bin\Debug
    	? CurDrive()	// C
    	? CurDir()	// XIDE\Projects\Project1\Bin\Debug 
    	?
    	DirChange ( "D:\TEst" )
        	?
    	? GetDefault()	// C:\XIDE\Projects\Project1\Bin\Debug // <--  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

    Please Log in or Create an account to join the conversation.

    Disk functions 24 Apr 2021 21:15 #18157

    • Сергей
    • Сергей's Avatar


  • Posts: 4
  • 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.

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1