Skip to main content

[archive] Finding files.

  • March 3, 2008
  • 13 replies
  • 0 views

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.

13 replies

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
FindFirstFile is definitely the choice if you are on Windows exclusively. It is certainly a minor issue that it does not accept the part path. May I see what path you give it? Or preferably a code example of a search?

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
I took it one step further, since the file I was looking for was a DLL that needed to be in the path, I parse the path variable and use that with the "C$FILEINFO" call to determine if it is accessable. This eliminated the need to use the FindFirstFile function call, so I've already deleted that code. Anyway, I tried several variations such as "c:\\*\\mdll.dll" "c:\\*mdll.dll", etc... and had no luck.

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
I take it you are looking for a file named mdll.dll, or does it have a prefix?
At any rate, neither the C$FILEINFO nor FindFirstFile will find the file automatically for you. FindFirstFile along with FindNext will help you parse the content of a directory given by you, it will then return each individual entry matching your search pattern, if it is not what you are looking for, you will have to fetch next (FindNext). To parse directories recursively you will have to test if the directory bit it set and do a new search in this. I take it this was not what you had in mind?

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
I take it you are looking for a file named mdll.dll, or does it have a prefix?
At any rate, neither the C$FILEINFO nor FindFirstFile will find the file automatically for you. FindFirstFile along with FindNext will help you parse the content of a directory given by you, it will then return each individual entry matching your search pattern, if it is not what you are looking for, you will have to fetch next (FindNext). To parse directories recursively you will have to test if the directory bit it set and do a new search in this. I take it this was not what you had in mind?

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
Question: Does your code have to be entirely hidden, or would it be okay if the standard Windows Find File dialog show?

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
I would want it to be hidden. The idea is to find a specific DLL to determine if the software that we interface to is installed. This way we can put a more descriptive message on the screen explaining to the customer that the other software must be installed before we can interface to that application. Just calling the DLL and letting the standard message come up can be confusing at times. The other reason is to determine what version of application is installed. One of the apps that we interface to has several different versions and the only way to determine that is to look for the different DLL files that get installed when their app is installed. Currently, we have to ask what version they are running and install appropriate software to go along with that version. I'm attempting to do away with that by looking at what version is installed and simply controlling it within one program instead of having to have several.

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
I take it you are looking for a file named mdll.dll, or does it have a prefix?
At any rate, neither the C$FILEINFO nor FindFirstFile will find the file automatically for you. FindFirstFile along with FindNext will help you parse the content of a directory given by you, it will then return each individual entry matching your search pattern, if it is not what you are looking for, you will have to fetch next (FindNext). To parse directories recursively you will have to test if the directory bit it set and do a new search in this. I take it this was not what you had in mind?


So would you use FindFirstFile to find the root directory of the drive you want to search, then FindNext to search for the exact file you want? I didn't see anything in the SDK documentation for a funtion FindNext, But I did for FindNextFile and it requires a handle for input from the FindFirstFile call, which would be pointed to the root directory.

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
I take it you are looking for a file named mdll.dll, or does it have a prefix?
At any rate, neither the C$FILEINFO nor FindFirstFile will find the file automatically for you. FindFirstFile along with FindNext will help you parse the content of a directory given by you, it will then return each individual entry matching your search pattern, if it is not what you are looking for, you will have to fetch next (FindNext). To parse directories recursively you will have to test if the directory bit it set and do a new search in this. I take it this was not what you had in mind?


So would you use FindFirstFile to find the root directory of the drive you want to search, then FindNext to search for the exact file you want? I didn't see anything in the SDK documentation for a funtion FindNext, But I did for FindNextFile and it requires a handle for input from the FindFirstFile call, which would be pointed to the root directory.

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
Could you determine whether it's installed and what version from the Windows Registry instead?

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
Could you determine whether it's installed and what version from the Windows Registry instead?


Possibly, on the newer versions, I don't think they have always used the Windows Registry to log their installs.

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
Ok, here goes.
First of all, today making a generic search on a system is likely to take ages. So I would not recommend that.
What we do know is that if the runtime shall find a DLL, it has to be in the search path.
The search path may be CODE-PREFIX, Windows directory or System directory, or if CODE-PREFIX is not set, it will search the Windows system path including Windows and system directory. If the software is properly installed, the DLL you want have to be in one of these directories.
Presuming that you know the full name of the DLL, what I would do then, is to check all of these directories explicitely.
So, first: Accept CODE-PREFIX and use UNSTRING DELIMITED BY ";" into an adequate number of substrings.
Concatenate the dll name to the substrings, remember to check that there is a terminating \\ to the substrings. Use the full path name with c$fileinfo, which will fail if the file does not exist.
If CODE-PREFIX is set, but the DLL not found, inspect the Windows and System directories specifically.
If CODE-PREFIX is not set, do the same, but by ACCEPT PATH from ENVIRONMENT.
If you by now have not found it, you should suggest the user install the software, because even if it is installed you will not be able to run it as the DLL is not in the search path for the runtime.
Hope this helps.

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
Ok, here goes.
First of all, today making a generic search on a system is likely to take ages. So I would not recommend that.
What we do know is that if the runtime shall find a DLL, it has to be in the search path.
The search path may be CODE-PREFIX, Windows directory or System directory, or if CODE-PREFIX is not set, it will search the Windows system path including Windows and system directory. If the software is properly installed, the DLL you want have to be in one of these directories.
Presuming that you know the full name of the DLL, what I would do then, is to check all of these directories explicitely.
So, first: Accept CODE-PREFIX and use UNSTRING DELIMITED BY ";" into an adequate number of substrings.
Concatenate the dll name to the substrings, remember to check that there is a terminating \\ to the substrings. Use the full path name with c$fileinfo, which will fail if the file does not exist.
If CODE-PREFIX is set, but the DLL not found, inspect the Windows and System directories specifically.
If CODE-PREFIX is not set, do the same, but by ACCEPT PATH from ENVIRONMENT.
If you by now have not found it, you should suggest the user install the software, because even if it is installed you will not be able to run it as the DLL is not in the search path for the runtime.
Hope this helps.

[Migrated content. Thread originally posted on 29 February 2008]

I'm working on a program where I need to determine if certain files exist anywhere on the hard drive of the pc. The only problem is the files that I'm searching for may be in a variety of different directories.

I tried using the "C$FULLNAME" library call as it says it will find the file and return the full path name for that file. However, I haven't had any success in it doing any kind of search for the file.

I also tried using a windows API call "FindFirstFile" using wildcards and such. This call will find the file if I give it the full path, but if I don't have the exact path, it returns an invalid handle and no file data.

I know I could use a system call to do a "DIR /s" and re-direct that to a file, but I was hoping to avoid that archaic method.

Any suggestions would be appreciated.
Thanks Gisle,
That's exactly what I had decided to do, as you say, if the DLL is properly installed it will be in the PATH variable. I do an ACCEPT PATH from ENVIRONMENT and parse through the paths until I find the DLL. If I don't find it, I display a message to that effect. That's what I had posted back on the 10th. my decision to do it that way. My other thoughts were that it would be nice if there was a way to search for specific files that may not be in the path. Just something for future references, but we have a Install shield that does this and we use the FindAllFiles routine to find certain files from old software that may not have any install shield information. Anyway, it allows us to find those files with a single command.

Thanks again for you help Gisle.