FileExists() returns false, even if file exists

别说谁变了你拦得住时间么 提交于 2019-12-06 23:58:14

问题


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?


回答1:


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.




回答2:


Not much information to go on, the code you are using might help, but could this be a 64 bit issue and that the dll is actually in the SysWOW64 folder? See here for a good description of the how this works.




回答3:


You are almost certainly not specifying the full or valid relative path of the file in your FileExists call. LoadLibrary will search certain locations (those where dlls are expected to reside) for you, but FileExists will not. Supply the complete and correct path and FileExists will work correctly.



来源:https://stackoverflow.com/questions/7627331/fileexists-returns-false-even-if-file-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!