FileType yielding incorrect values
BlitzMax Forums/BlitzMax Programming/FileType yielding incorrect values
| ||
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! :( |
| ||
At a quick glance, try replacing Print FileType(g) + " " + g with Print FileType("media\"+g) + " " + g |
| ||
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! :( |
| ||
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. |
| ||
...No point having three posts containing the same code... |
| ||
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" NextEdit: Hee-hee! Three posts to choose from. I still prefer my LoadDir() method though. |
| ||
I still prefer my LoadDir() method though. So do I. |
| ||
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. ;) |