News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

find a file

Started by franlou, June 07, 2010, 01:11:56 PM

Previous topic - Next topic

clive

Yes, it is searching "C:" for occurrences of the file. Do you know the first occurrence is the correct one, as there is no guarantee that is the case? It will basically find any/ALL files which have this name. One would normally search directories in the PATH (environment variable), SYSTEMROOT, or PROGRAMFILES for standard applications.

To find the first match and then stop, you will have to write code to exit the loop and unwind/terminate the recursion. Would an example in C be instructive?
It could be a random act of randomness. Those happen a lot as well.

dedndave

one approach would be to read the default registry value for [HKEY_CLASSES_ROOT\Applications\wordpad.exe\shell\open\command]
that way, you don't have to search at all   :bg
the WordPad.exe file is sometimes not located in the Windows\System32 folder, or in any of the PATH'ed folders

clive

I guess I would be interested in more details of the actual purpose for this code. And why more classical approaches might not work. For example there are forms of spawn() that will search for executables.

As Dave indicates there are many ways to narrow the search, and then expand it when the more "usual" locations have been eliminated, and finally doing a whole drive search. I will note that the search order for directories/files provided by FindFirstFile/FindNextFile is some what arbitrary, based on the order they were created in the file system. A more complicated solution is to sort the names during gathering, and then descend the directories in alphabetic order, or go with the file system optimized order and either queue the directories for descent, or sort the whole tree laters.

I would also worry about some clown calling their file WORDPAD.EXE to catch people/applications that spider the drive in this fashion.
It could be a random act of randomness. Those happen a lot as well.

franlou

In fact my problem is this:
in 2000, I made an application which could have need (only sometimes ) of 'Wordpad.exe' and I needed to locate it .
So I stored the path of this application in registry, in a record user-specific data under the HKEY_CURRENT_USER key

with the old versions of windows I looked for 'wordpad.exe', and I stored the path ; It was nice with Windows9x, but not later...

So the routine that clive display ALL 'wordpad.exe'; I did not know that they had  several;

I wish get ONLY   the path of application  : here (Windows vista)   "C:\ProgramFiles\WindowsNT\Accessories\wordpad.exe" to store it in registry

is it always the  same path in diffent version of Windows? if yes my problem is resolved.

thank's





dedndave

it may be in different places for different versions of windows
you should have a look at the registry value:

[HKEY_CLASSES_ROOT\Applications\wordpad.exe\shell\open\command]

the information you want is already stored in the registry for you
it is unicode text, so each character is followed by a null (0 byte)
under XP, the value is:

"%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"

you can strip off the "%1" and expand the environment variable %ProgramFiles% and have a complete path

otherwise, you could look in that specific folder first
then, look in %SystemRoot%\System32, then %SystemRoot%

but, it is probably "the proper way" to look at the registry value