File.Exists对不存在的文件返回true [英] File.Exists returning true for a file that doesn't exist

查看:1189
本文介绍了File.Exists对不存在的文件返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该文件将文件保存在Path.GetDirectoryName(FilePath)中,其中FilePath = Application.ExecutablePath包含一些有关许可的信息.如果我从VS运行程序,则可以正常运行,但是如果我进行安装并安装然后运行它,则程序认为该文件已存在.我更改了程序,以在消息框中显示我的FilePath以及File.Exists(FilePath)返回true还是false.因此,我查看了该路径,启用了显示隐藏文件和系统文件的功能,F5进行了几次,什么也没有.该文件不存在,但是File.Exists(FilePath)返回true.知道为什么会发生这种情况吗?我该如何解决呢?

I'm working on an app that saves a file in Path.GetDirectoryName(FilePath) where FilePath = Application.ExecutablePath that contains some information about licensing. If I run the program from VS it works OK but if I make an installer and install and then run it, the program thinks that the file already exists. I changed my program to show on a message box my FilePath and whether File.Exists(FilePath) returns true or false. So I looked in that path, enabled showing hidden and system files, F5'd several times and nothing. The file doesn't exist, but File.Exists(FilePath) returns true. Any idea why cold this be happening and how can I work around it?

我正在使用Windows Vista,Visual Studio 2010和C#,并通过VS的安装项目创建了我的安装程序.

I'm using Windows Vista, Visual Studio 2010, C# and created my installer with VS's Setup Project.

我的路径是: C:\ Program Files(x86)\ Helium \ License.xml .

这是我的代码的一部分:

This is part of my code:

        MessageBox.Show("LicenseFileName: " + LicenseFileName); // LicenseFileName: C:\Program Files (x86)\Helium\License.xml
        System.Diagnostics.Process.Start(LicenseFileName);      // Nothing happens
        MessageBox.Show("File.Exists(LicenseFileName): " + File.Exists(LicenseFileName)); // File.Exists(LicenseFileName): true

忘记说我之前已经安装了该应用程序,因此该文件曾经存在.我是使用控制面板"卸载的.

Forgot to say that I already had the application installed before so the file used to exist. I uninstalled using Control Panel.

推荐答案

如果要安装到系统文件夹,则可能会启动Windows文件虚拟化并为每个用户创建文件副本.因此,您的文件可能位于%userprofile%\ AppData \ Local \ VirtualStore文件夹

If you are installing to a system folder, it is possible that Windows file virtualization kicked in and created a per user copy of the files. So your files may be located somewhere in %userprofile%\AppData\Local\VirtualStore folder

这篇关于File.Exists对不存在的文件返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆