FileType() fails with trailing slash

Archives Forums/BlitzMax Bug Reports/FileType() fails with trailing slash

GfK(Posted 2011) [#1]
Wasted an hour this morning tracking this down.

Print FileType("C:/windows")

Result: 2 (FILETYPE_DIR)

FileType("C:/windows/")

Result: 0 (FILETYPE_NONE)


JoshK(Posted 2011) [#2]
In that path the file directory is "C:/windows" and the file name is "", so that is the result I would expect.


BlitzProg(Posted 2011) [#3]
if you want to FileType "windows" without removing the slash, you need to add a dot. ;)
FileType("C:/windows/.")



Ghost Dancer(Posted 2011) [#4]
I've just spent ages on this too, must have changed in a recent update as it previously worked with the trailing slash. I've written a StripSlash replacement function to remove the trailing slash:

Print FileType(StripSlashes(path$))

Function StripSlashes$(path$)
'Replacement for StripSlash() but does not reformat text and removes both types of slash.
'Does not strip slash from a root' path (e.g. "/" or "C:/")
	Local pathLen% = Len(path$)
	
	If pathLen > 3 Then
		Local char$ = Right(path$, 1)
		
		If char$ = "\" Or char$ = "/" Then path$ = Left(path$, pathLen-1)
	End If
	
	Return path$
End Function


Last edited 2011