FileSystem

BlitzMax Forums/BlitzMax Programming/FileSystem

Hi,

Why do all the file commands like RealPath ect convert \ to / for dir paths ?

I don't know why, but I think in "%BlitzMax%\mod\brl.mod\filesystem.mod\filesystem.bmx" should
Function FixPath( path$ Var,dirPath=False )
	If Not path Return
	path=path.Replace("","/")
?Win32
	If path.length>=2 And path[1]=Asc(":")
		If path.length=2 Or path[2]<>Asc("/") path=path[..2]+"/"+path[2..]
	EndIf
?
	If dirPath path=StripSlash(path)
End Function

be changed to
Function FixPath( path$ Var,dirPath=False )
	If Not path Return
	path=path.Replace("","/")
?Win32
	path=path.Replace("/","")
	If path.length>=2 And path[1]=Asc(":")
		If path.length=2 Or path[2]<>Asc("/") path=path[..2]+"/"+path[2..]
	EndIf
?
	If dirPath path=StripSlash(path)
End Function

This would work.

yup, i done a replace, thanks mate.

Why do all the file commands like RealPath ect convert \ to / for dir paths ?
Because unlike certain other programs, BlitzMAX is POSIX compliant.

Sorry!
But my changes of FileSystem will not work correctly!
There should be changed more than only FixPath...
For example RealPath(...) will not work.
Better do this:
'First set FixPath(...) like it was before any changes:

Function FixPath( path$ Var,dirPath=False )
	If Not path Return
	path=path.Replace("","/")
?Win32
	If path.length>=2 And path[1]=Asc(":")
		If path.length=2 Or path[2]<>Asc("/") path=path[..2]+"/"+path[2..]
	EndIf
?
	If dirPath path=StripSlash(path)
End Function

'Then write this function:

Function GetOSPath$ ( POSIXPath$ )
?Win32
  Return POSIXPath.Replace ( "/" , "" )
?
  Return POSIXPath
EndFunction

'And replace each command like this:
Return path
'To:
Return GetOSPath ( path )

'For example change:

Function ExtractDir$( path$ )
	FixPath path
	Local i=path.FindLast("/")
	If i=-1 Or i=path.length-1 Return BAD_DIR
	path=path[..i]
	FixPath path
	Return path
End Function

'To:

Function ExtractDir$( path$ )
	FixPath path
	Local i=path.FindLast("/")
	If i=-1 Or i=path.length-1 Return BAD_DIR
	path=path[..i]
	FixPath path
	Return GetOSPath(path)
End Function