Im making a program that puts the "data" in ".\data", the program dir. itself and then the "subdirectory" "data". I want to list the files that are in the "data" directory. For that propouse im using "FindFirstFile". But i dont understand very well how it works.
I put to find ".\data\*" and dont find any file (i have created one for testing). Then i try "./data/*", and dont work. But i try "./data/N*" and it finds the file. (NOTERASE.TXT is the name of the file) altought microsoft say that "/" is a reserved char.
But what i want to do is to "list - find" all the files in the dir. How do i do it?. What is the wilcard "?" for? i have tested too, but it dont find anything. To get to the point i dont want to have a file in the dir to find the other files :rolleyes:.

Excuse a large post.
Posted on 2004-03-23 09:22:00 by Ateneo
It sounds somewhat weird that "./data/N*" works but "./data/*" doesn't. As for the '/' deal, '/' is translated to '\' internally - at least on a lot of APIs. I don't know if it's documented behaviour, so I certainly wouldn't depend on it.

Also, be careful when using relative paths! Your program could be started with a working-directory different from the directory the .exe is in, this would foil your data access scheme. The best way would be to GetModuleFileName(NULL, buf, sizeof(buf)), chop off the filename part, and then use this base directory everytime you need to reference a file with a relative path. It's more work, but it will guarantee your application works.

The '?' wildcard character means "match any single char".
Posted on 2004-03-23 10:32:47 by f0dder
Tanks for the information and i will take what you say account, i mean i will make what you describe for finding the main exe folder.
Posted on 2004-03-23 13:41:00 by Ateneo
As for your problem, I am still sortof puzzled by it. The structure should be 4-byte aligned, and perhaps you might want try zeroing all the fields of it before the FindFirstFile call. If you're using C/C++ or some c-string macro in masm, perhaps your problem is that you should use "\\" instead of "\". Put your failing asm code in a .zip and post it here?
Posted on 2004-03-23 13:54:13 by f0dder
You might try this as well, otherwise it will only find files with no extension.

Posted on 2004-03-23 14:12:31 by donkey
Hrm... at least in NT cmd.exe, "*.*" will only find files with an extension, and will NOT find files WITHOUT an extension - so on NT, "*" is the generic string to use. Dunno about 9x, and if I'd have to choose, of course I'd choose the NT-specific behaviour - 9x is dead, and an abomination that should never have existed ^_^

(If the behaviour is cmd.exe specific and not FindFirstFile specific, that's a completely different matter though)
Posted on 2004-03-23 14:25:41 by f0dder
Win9X behaves just like DOS, like Donkey pointed out. FindFirstFile works like that too under Win9X, but I didn't test it under XP. However I suppose it works like that too... it would break a lot of code if it didn't. :confused:
Posted on 2004-03-23 16:56:50 by QvasiModo
Ok, on win2ksp4 "*", "*.*" and "*.*.*" all return the same thing - I guess it's just the cmd.exe shell that has some different filename expansion (like, "dir *.*" only shows files with extensions, "dir *" shows everything, "dir *." only shows files without exts).

But crappy old 9x requires "*.*" in FindFirstFile to get all files?
Posted on 2004-03-23 17:09:57 by f0dder

But crappy old 9x requires "*.*" in FindFirstFile to get all files?

AFAIK yes, but then again I never thought it wouldn't... so let me check first :)
Posted on 2004-03-23 17:58:33 by QvasiModo
FindFirstFile() on 9x does not need '*.*'. Single asterisk is enough for finding all files. I don't know if '*.*' returns different things, though.

About '/' as a dir separator, it is documented somewhere in SDK, although MS discourages using it. I remember reading it, but can't find where it was.
Posted on 2004-03-23 18:45:34 by Starless
OP's problem is a puzzle to me. I've been coding my FindFirstFile() arg with single asterisk and had no problem whatsoever.

Did you get '.' and '..'? If you did, you should have your file name somewhere in repeated calls to FindNextFile(). Or, did you expect FindFirstFile() to omit '.' and '..'?
Posted on 2004-03-23 18:54:38 by Starless
Thanks starless, that was my problem.

And changing the topic-> how do i do to show a photo-pic in the board when i post?
Posted on 2004-03-23 21:12:52 by Ateneo
"user cp" -> "edit options" -> Avatar
Posted on 2004-03-24 09:44:30 by f0dder
Just a note. I use to use FindFileFirst but found when i needed to cross to the virtual files and folders that i could not find it.

Reverted to COM, and that makes system platform indapendant so win9x and NT 4 find the same results and so it will be cross-platform supported within a Microsoft enviroment.

{why keep on coding the same prog for each platform??}
Posted on 2004-03-25 17:56:09 by Black iCE