Reading a file help please

BlitzPlus Forums/BlitzPlus Programming/Reading a file help please

William Drescher(Posted 2007) [#1]
I'm trying to make a regisrty editor (that does not affect the real registry) that will help me keep track of my projects by archiving their data in the registry I made. It works by using files in locations in the main dir like "Blitz\BP\Projects\BlitzRegEdit.c" and i'm trying to use the NextFile command to read the data to find the file, but it never adds anything to the treeview area of the program.

Here is the loader, It's kinda crummy since I through it together in about 1 minute and expected it to work pretty well the first time, but to no avail.

Function LoadApplicableData()
	Local Dir = ReadDir("Blitz")
	Local File$
	Local BFile
	While FileType(BFile)<>0
	File$ = NextFile(Dir)
	BFile = ReadFile(File)
	If FileType(BFile)=1 Then
		N.Node = New Node
		N\Txt$ = File$
		N\Dat = AddTreeViewNode(ProgNode,N\Txt$)
	EndIf
	Wend
End Function


Please someone help me fix this code to actually work!!!


JazzieB(Posted 2007) [#2]
You're trying to get the file type with a file handle. FileType accepts the path of a file, not a file handle (which you created with ReadFile).

Also, you're not closing the directory reading with CloseDir. And you don't need ReadFile unless you're going to read any data from the file (you will also need CloseFile if you do need to use ReadFile).

Function LoadApplicableData()
	Local Dir = ReadDir("Blitz")
	Local File$
	Repeat
	File$ = NextFile(Dir)
	If FileType(File$)=1 Then
		N.Node = New Node
		N\Txt$ = File$
		N\Dat = AddTreeViewNode(ProgNode,N\Txt$)
	EndIf
	Until File$=""
End Function

Try that. Not tested though.


William Drescher(Posted 2007) [#3]
Thanks, most of the things about the closing files and dirs i have in the real code, it was just left out by accident in the snipet.


William Drescher(Posted 2007) [#4]
Ok, I tried it and I didn't get any error, but I still can't get it to put a new node in the treeview for some reason. Any thoughts on this?


skidracer(Posted 2007) [#5]
I think you need to add the original directory path to the filename as in File="Blitz/"+NextFile(dir).


William Drescher(Posted 2007) [#6]
Do you mean like this:

Function LoadApplicableData()
	Local Dir = ReadDir("Blitz")
	Local File$
	Repeat
	File$ = "Blitz\"+NextFile$(Dir)
	If FileType(File$)=1 Then
		N.Node = New Node
		N\Txt$ = File$
		N\Dat = AddTreeViewNode(ProgNode,N\Txt$)
	EndIf
	Until File$=""
End Function


I have already established that it is finding the files and reading from them, I just can't get the node to actually appear in the tree view. I think it might be a Global vs. Local problem or something, but the whole tree view root and it's sub-roots are global.

Any thoughts?