Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileExists() returns false, even if file exists

I want to check if a dll in System32 directory (Windows 7) exists. But even if it exists, FileExists() returns false. LoadLibrary returns a valid handle. In this case, I only want to check, if the files exists and visualize this information. Do you have a any tips to solve this?

like image 652
SevenEleven Avatar asked Oct 02 '11 15:10

SevenEleven


People also ask

Why is file exists false?

The Exists method returns false if any error occurs while trying to determine if the specified file exists.

Which method of the class returns true if the file exists otherwise returns False?

exists() method. The idea is to use the File. exists() method to determine whether a file denoted by a specified pathname exists. This method returns true if the file exists; false otherwise.

How do you check if a file already exists?

To check if a file exists, you pass the file path to the exists() function from the os. path standard library. If the file exists, the exists() function returns True . Otherwise, it returns False .

Does file exist Java?

To test to see if a file or directory exists, use the “ exists() ” method of the Java java. io. File class. If the exists() method returns true then the file or directory does exist and otherwise does not exists.


1 Answers

Most likely this is down to file redirection. You have a 64 bit machine but from the 32 Delphi process, Windows\system32 actually redirects to Windows\Syswow64. So when you think you are asking for the existence of a file in Windows\system32, the system is actually reporting the existance (or otherwise) of a file in Windows\Syswow64.

If you really do need to see into the true 64 bit system32 then you need to disable file redirection. You can do this with the Wow64DisableWow64FsRedirection() function. Don't forget to switch it back on with Wow64RevertWow64FsRedirection(). Beware that disabling the redirector has wide reaching effects and can result in very strange behaviour so do so with care.

like image 142
David Heffernan Avatar answered Sep 18 '22 18:09

David Heffernan