fbpx

DirMake() and DirRemove()

  • Karl-Heinz Rauscher
  • Karl-Heinz Rauscher's Avatar Topic Author
  • Offline
More
2 months 1 week ago #1 by Karl-Heinz Rauscher
DirMake() and DirRemove() was created by Karl-Heinz Rauscher
Hi Chris and Robert,

compared to VO:

Dirmake() returns -1 instead of 183 ( "already exists" ) if the dir to create already exist.
DirRemove() returns -1 instead of 2 ( "dir not found" ), if the dir to remove doesn´t exist.

In GitHub i see that the Ferror() value setting was added to both funcs. i´ve made some tests in VO and noticed that VO doesn´t set the Ferror() value in both funcs.

About the possibility that Dirmake() or DirRemove() might return -1 the VO-Help says:

[...]
0 if successful; -1 if there is an argument error; otherwise, the DOS error code
[...]

Strange - what else than a DOS error is an "argument" error ? I´ve tried both funcs with several wrong params but I did not manage it that VO returns -1, it always ends up with a known Dos error.

so both funcs might look:
FUNCTION DirMake (cDir AS STRING) AS INT
	LOCAL result AS INT 
	
	TRY

		IF !Directory.Exists(cDir)
			Directory.CreateDirectory(cDir)
			result := 0
		ELSE
			result := 183  // "dir already exists"  instead of -1
		ENDIF 
		
	CATCH e AS Exception 

    
		result := (INT) GetErrorCodeFromException ( e ) 		
        
        
	END TRY 

	
	
RETURN result


FUNCTION DirRemove(cDir AS STRING  ) AS INT
	LOCAL result AS INT 
	
	TRY
         
		IF Directory.Exists(cDir)
			Directory.Delete(cDir,FALSE )
			result := 0
		ELSE
			result := 2  // "Dir not found" instead of -1
		ENDIF

	CATCH e AS Exception
	
     
		result := (INT) GetErrorCodeFromException ( e ) 		
           
          
	END TRY

RETURN result


what do you think ?

regards
Karl-Heinz

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

More
2 months 1 week ago #2 by Robert van der Hulst
Replied by Robert van der Hulst on topic DirMake() and DirRemove()
Karl-Heinz,

It makes sense to change this.
Will be included in next build.

Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

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

  • Karl-Heinz Rauscher
  • Karl-Heinz Rauscher's Avatar Topic Author
  • Offline
More
2 months 1 week ago #3 by Karl-Heinz Rauscher
Replied by Karl-Heinz Rauscher on topic DirMake() and DirRemove()
Hi Robert,

if a dir doesn´t exist the current DirChange() implementation throws -1 too.

FUNCTION DirChange (cDir AS STRING) AS INT
	LOCAL result AS INT 
	
	
	TRY 
		
		IF Directory.Exists(cDir)
			Directory.SetCurrentDirectory(cDir )
			result := 0 
			
		ELSE 	
			result := 3  // "path not found"  instead of -1
			
		ENDIF
		
	CATCH e AS exception 
	
		result := (INT) geterrorcodefromException(e)                          
		
	END TRY
	
RETURN result


@All: What might be the most dangerous x# overload of all times ? :unsure:
.
.
.
.
.
.
.
.
.
.
.
.
.
FUNCTION DirRemove(cDir AS STRING ) AS INT
	RETURN DirRemove2(cDir , FALSE ) 
	
FUNCTION DirRemove(cDir AS STRING , lRecursive AS LOGIC ) AS INT
	LOCAL result AS INT 
	
	TRY
         
		IF Directory.Exists(cDir)
			Directory.Delete(cDir, lRecursive  )
			result := 0
		ELSE
			result := 3   // errorcode 3 - "Path not found" - instead of -1
		ENDIF 
		
	CATCH e AS Exception
    
		result := (INT) GetErrorCodeFromException ( e ) 
	           
          
	END TRY

RETURN result

:woohoo:

:-)

regards
Karl-Heinz

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