DirMake() and DirRemove()

This forum is meant for questions and discussions about the X# language and tools
Post Reply
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

DirMake() and DirRemove()

Post by Karl-Heinz »

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:

Code: Select all


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
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

DirMake() and DirRemove()

Post by robert »

Karl-Heinz,

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

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

DirMake() and DirRemove()

Post by Karl-Heinz »

Hi Robert,

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

Code: Select all

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:
.
.
.
.
.
.
.
.
.
.
.
.
.

Code: Select all

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
Post Reply