for LOOP reading files...

Blitz3D Forums/Blitz3D Beginners Area/for LOOP reading files...

Im trying to check if
001.ITM to 005.ITM exist but it wont work they say it doesnt exist..->[data]->[items]-> *.ITM

oh and is there a way to get how many .ITM there is in a directory?

For t = 1 To 5

file_num = 0 + 1
file_path = "data/items/00" + file_num + ".ITM"
filein = ReadFile (file_path)

If filein = False
	RuntimeError "Error could not read file"
Else
	Notify "File Reading Successful"
End If

CloseFile(filein)

Next


you should probably have:

file_num = t


Your current code will check for the existence of "001.ITM", 5 times.

Ok it still doesnt read the files it gives me an error what could be wrong.. cause 001.ITM, 002.ITM ... 003.ITM, 004.ITM, 005.ITM ... all exist... whats wrong?

For t = 1 To 5

file_num = t
file_path = "data/items/00" + file_num + ".ITM"
filein = ReadFile (file_path)

If filein = False
	RuntimeError "Error could not read file"
Else
	Notify "File Reading Successful"
End If

CloseFile(filein)

Next


You can always used the "FileType" function for this. It returns 0 if the file isn't there.

Declare file_path as a string variable using $. Like this:
file_path$="data etc

jhocking, hmm.... What?! Transforme that into newb explication plz ;)

In retrospect my post does look sort of like a cryptic Windows error message. I meant replace this line:
file_path = "data/items/00" + file_num + ".ITM"

with this:
file_path$ = "data/items/00" + file_num + ".ITM"

Note that the only change is adding $. I can never remember with complete certainty if you need to do that, but that is popping into my head.

file_path is an integer variable.
file_path$ is a string variable.

In your program, file_path will contain the value of zero, not the string data "data/items/00" + file_num + ".ITM"

Make the change jhocking said, and it will work.

Grr ... I always miss the obvious error. :)

Well, he also needed to make the change you noticed.