FileType yielding incorrect values

BlitzMax Forums/BlitzMax Programming/FileType yielding incorrect values

Drekinn(Posted 2008) [#1]
FileType is returning incorrect values when checking the contents of a directory. It's stating that both folders and files are the value 0, when in fact they should be values 2 and 1 respectively.

	Local dir:Int = ReadDir("media")
	Local g:String
	Repeat
		g = NextFile(dir)
		If g = "" Then Exit
		If g = "." Or g = ".." Then Continue
		Print FileType(g) + " " + g
	Forever
	CloseDir(dir)


Results:

0 folder
0 image.png
0 textfile.txt


What's going on? Please help! :(


Gabriel(Posted 2008) [#2]
At a quick glance, try replacing

Print FileType(g) + " " + g

with

Print FileType("media\"+g) + " " + g


Drekinn(Posted 2008) [#3]
Gabriel wrote:
At a quick glance, try replacing

Print FileType(g) + " " + g

with

Print FileType("media\"+g) + " " + g


No joy. Respecifying the "media" folder is not actually necessary as the folder is represented by the variable 'dir' (via ReadDir).


Is anyone else experiencing this FileType error, or is it just me? Could someone please check if this happens with them too? I must be able to determine the presence of files and folders! Argh! :(


tonyg(Posted 2008) [#4]
local mydir:String="media/"
local dir:Int = ReadDir(mydir)
Local g:String
	Repeat
		g = NextFile(dir)
		If g = "" Then Exit
		If g = "." Or g = ".." Then Continue
		Print FileType(mydir+""+g) + " " + mydir+""+g
	Forever
CloseDir(dir)

Basically, 'g' needs to have a fullpath.


Yan(Posted 2008) [#5]
...No point having three posts containing the same code...


SebHoll(Posted 2008) [#6]
Respecifying the "media" folder is not actually necessary as the folder is represented by the variable 'dir' (via ReadDir).

If you check the NextFile(), docs you'll see that it is necessary - NextFile() only returns the filename, and FileType() expects a full file path.

Try the following, and post the output:

Local tmpPath$ = "media"
For Local tmpFileName$ = EachIn LoadDir(tmpPath,True)
	tmpFileName = RealPath(tmpPath) + "/" + tmpFileName
	Print FileType(tmpFileName) + " ~q" + tmpFileName + "~q"
Next
Edit: Hee-hee! Three posts to choose from. I still prefer my LoadDir() method though.


tonyg(Posted 2008) [#7]
I still prefer my LoadDir() method though.

So do I.


Drekinn(Posted 2008) [#8]
Ahh, thanks all. Yes, including the full path in FileType was the answer; my apologies to Gabriel - you were correct (I'd left out the required "/"). Joy!

Thanks also to tonyg, Yan and SebHoll. ;)