SyntaxBoom

Languages & Coding => BlitzMax (NG/Vanilla variants) => Topic started by: Chalky on Jun 17, 2025, 11:42 PM

Title: NextFile oddity...
Post by: Chalky on Jun 17, 2025, 11:42 PM
I have been using NextFile quite happily for years to read the contents of directories and not had any problems [that I have been aware of].

However, I have noticed some strange results this week, when my trusty "get-directory-contents" routine started finding non-existent files.

The code I use originated in the BlitzMax help files and is nothing clever. Most of the time the resulting directory contents match that of File Explorer or Xplorer2 - but every now and then NextFile will "find" a file which doesn't exist [i.e. the file is not in Explorer and FileType() returns 0, as does FileSize()].

Does anyone have any idea why this might be happening?
Title: Re: NextFile oddity...
Post by: Midimaster on Jun 17, 2025, 11:54 PM
You write FileSize() returns 0?

A not existing file would return -1 if you scan it with FileSize().

What is the filename that NextFile() reports?
Title: Re: NextFile oddity...
Post by: Chalky on Jun 18, 2025, 12:10 AM
Sorry - my bad. FileSize() returns -1 [except every now and then it returns what looks like a valid value] and FileTime() always returns 0. There are several files which appear - not just one. It can be in any directory. It's as if it's detecting deleted files (that's just a guess, as some of them are in directories I wouldn't normally explore, and only did so while testing my program).

I can work round the problem by checking FileTime() but I'm totally baffled as to why it's happening in the first place...
Title: Re: NextFile oddity...
Post by: Midimaster on Jun 18, 2025, 07:31 AM
I cannot see the same problem on my computer. I tested the example code before and after I deleted some files:

'File System Example
SuperStrict
Local dir:Byte Ptr = ReadDir("C:/Users/Mydir/Documents" )
If Not dir Then
    RuntimeError "Cannot open folder"
End If
Local file:String
Repeat
    file = NextFile(Dir) ' Get the filenames in folder
    Print file   
Until file = ""
CloseDir(dir)

But both test runs showed exactly what I expected. Once with the files, then without the deleted files.

I would suggest not to use your app, but test the behaviour with the example code and see, whether you get the same wrong results. Additionally
I would suggest to expand this example with the following function to get more information about the "ghost files":

FileType()
RealPath()
FileExists()
FileTime()
FileSize()
FileMode()

Then I would suggest to copy one of this folders (with windows explorer) to an USB stick and see, what now the example reports about the content of the USB-Stick.

I guess, that not the Blitzax code is the problem, but the harddisk...
Title: Re: NextFile oddity...
Post by: Baggey on Jun 18, 2025, 08:54 AM
May not be related i couldn't save files to the C: drive directly. A windows security thing?

I could only save to a named folder already created!

If that helps great! If not ignore it! :D
Title: Re: NextFile oddity...
Post by: Chalky on Jun 18, 2025, 09:57 AM
Thanks Baggey!

There's nothing wrong with my code - I've been using the exact same functions (via "Include") for years without issues.

However - you're idea of copying to another drive was genius - as after doing so my program scanned the 'new' folder and did not find anything which did not exist.  ;D

You are therefore correct - it is the hard drive (SSD) which is causing the problem rather than BlitzMax. At least this means I can carry on programming in the knowledge that it is working correctly despite what I'm seeing on screen (the problem only occurs with folders on the "C:/" drive).

Sadly I have no idea what I can do to correct the underlying problem...  :(
Title: Re: NextFile oddity...
Post by: Jackdaw on Jun 18, 2025, 10:06 AM
Try running the usual standard M$ Windows drive checks. And if the SSD has software from the manufactures, then run the manufacture's test tools.
Title: Re: NextFile oddity...
Post by: Chalky on Jun 20, 2025, 08:27 AM
Well - I have run every check I can think of on the SSD (including those supplied by Crucial, as suggested) without any errors.

However (and this is the REALLY weird part):

1) If I load the source into MaxIDE or BLide and run it (with debug on or off - it doesn't make any difference) NextFile finds files which do not exist.
2) If I double click the .exe created by MaxIDE or Blide in step 1 from File Explorer, no non-existent files are found.

This makes no sense to me. The same .exe file is running in steps 1 and 2. Why then, if being launched from within an IDE, do things not work as expected?

PS: No reply expected - though it would be nice to understand what's going on...
Title: Re: NextFile oddity...
Post by: Baggey on Jun 20, 2025, 09:10 AM
Do You switch between Blide and Normal BlitzmaxNG editor dont like each other?

If you use BLide it currupts the files and BlitzmaxNG then has problems with it.

Try cutting and pasting your code in to note pad or something.

Delete every file you see related to the old stuff!

Now Create a new blank file and cut and paste your text back in and resave!

This happend to me with some projects i was working on and solved the problem. I can still save stuff to the C drive as long as it goes in a Folder first.  ::)

Whilst Blide is a nice looking ide BlitzmaxNG IDE out of the box, is all i work with since that happened to me. I also remember stuff getting altered by the VisualStudio Blitz app as well.

Kind Regards Baggey