[英]File.Exists() returns false for some files under Program Files
I thought it was due to some permission issue, but that does not seem to be the case.我认为这是由于某些权限问题,但似乎并非如此。 The file has "Read & Execute, Read" permissions for "Users", and "Full control" for "Administrators" and "SYSTEM".该文件对“用户”具有“读取和执行、读取”权限,对“管理员”和“系统”具有“完全控制”权限。 Can there be other reasons why File.Exists()
returns false
? File.Exists()
返回false
是否还有其他原因?
PS: I did not think the code was important, so I did not type the code, but if that is the rule, here is the text version of the code. PS:我认为代码不重要,所以我没有输入代码,但如果这是规则,这里是代码的文本版本。
static void Main(string[] args)
{
var app = @"C:\Program Files(x86)\VideoLAN\VLC\vlc.exe";
var psi = new ProcessStartInfo();
psi.FileName = Path.GetFileName(app);
psi.WorkingDirectory = Path.GetDirectoryName(app);
Process.Start(psi);
}
Anyway, there seems to be a weird behaviour of pasting path in Visual Studio.无论如何,在 Visual Studio 中粘贴路径似乎有一种奇怪的行为。 If I use "Copy as path" in File Explorer and paste it into an empty string, VS removes the space between Files
and (x86)
.如果我在文件资源管理器中使用“复制为路径”并将其粘贴到一个空字符串中,VS 会删除Files
和(x86)
之间的空格。
On your file-system, there's a space between Files
and (x86)
.在您的文件系统上, Files
和(x86)
之间有一个空格。 You don't have that in the string you're using to get at the file, so it should be changed to:您用于获取文件的字符串中没有它,因此应将其更改为:
var app = @"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe";
// ^
// need this
In terms of your statement that:就您的陈述而言:
Anyway, there seems to be a weird behaviour of pasting path in Visual Studio.无论如何,在 Visual Studio 中粘贴路径似乎有一种奇怪的行为。 If I use "Copy as path" in File Explorer and paste it into an empty string, VS removes the space between
Files
and(x86)
.如果我在文件资源管理器中使用“复制为路径”并将其粘贴到一个空字符串中,VS 会删除Files
和(x86)
之间的空格。
That's almost certainly down to auto-formatting, which is done on paste among other things (though you can disable it, or use CTRL+Z to back up, since it appears to paste and then format).这几乎可以肯定归结为自动格式化,这是在粘贴等操作时完成的(尽管您可以禁用它,或者使用CTRL+Z进行备份,因为它似乎是粘贴然后格式化)。
Since you paste a "quoted thing"
inside quotes to end up with ""quoted thing""
, the quoted thing
bit is now outside quotes and therefore subject to auto-formatting.由于您将"quoted thing"
粘贴在引号内以以""quoted thing""
结尾,因此quoted thing
位现在在引号之外,因此会受到自动格式化。
Had you copied the file name without the quotes, or copied it with the quotes but pasted to a non-quoted area, I suspect it would have been put in unmodified (as a quoted string).如果您复制了不带引号的文件名,或者复制了带引号的文件名但粘贴到了未引用的区域,我怀疑它会未经修改(作为带引号的字符串)被放入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.