Nextfile/Filetype problem.

Blitz3D Forums/Blitz3D Beginners Area/Nextfile/Filetype problem.

Farflame(Posted 2005) [#1]
I'm using nextfile to run through a list of files in a folder. Couple of problems.....

Most importantly, it's finding my file, which the program itself has just created, but then when I use 'Filetype' on it, it tells me the file doesn't exist... how can file not exist which Nextfile has just found?

Here's that bit of code.

file$=NextFile$(mydir)
If file$="" Then Exit
If FileType(file$)=1 Then....

But it's reporting a zero so it's not carrying on from there.

Secondly, Nextfile first finds two 'files' named '.' and '..'. Are these supposed to be there? It's a brand new created folder.


Beaker(Posted 2005) [#2]
If the program has just created the file, why do you need NextFile() at all?

Why not just check the filename (that was just created) itself?

"." and ".." are 'folders' representing the "root" folder and the "parent" folder respectively.


Farflame(Posted 2005) [#3]
That's the second part answered then - so they're always there?

The program created the file earlier in a previous function, but now I'm trying to scan through all the files in a folder. One file DEFINATELY exists (I'm looking at it in it's folder), so why does FileType(file$) say it doesn't? I need to do it this way as I need to scan through all the files.


big10p(Posted 2005) [#4]
As Beaker said, the "." and ".." files are actually directories. If you use FileType on these, it will return 2. This will cause the line "If FileType(file$)=1 Then..." to fail.

Could this be the cause of your problem?


Farflame(Posted 2005) [#5]
Unfortunately not. I only noticed those files when I ran it through the debugger, and in the first two loops it finds them, and ignores them (as it should do). On the third pass, nextfile DOES find my file (which exists in the folder) which is a simple text file, but then Filetype returns a zero on it... :(

Quite an odd one, I can't see what's wrong. Probably just a typo but it's very odd that nextfile finds it, which means it's there, then filetype doesn't recognise it... ?


Farflame(Posted 2005) [#6]
Ah, I've solved it. Apparently filetype needs to know the whole path, so 'if filetype(file$)=1' should be 'if filetype(folder$+"\"+file$)=1' .... since my file was two folders down from the root.