DirectoryInfo.GetFiles方法不返回任何文件 [英] DirectoryInfo.GetFiles method not returning any files

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

问题描述

我正在尝试返回%WINDIR%\System32\inetsrv\config中存在的.config文件.

I'm trying to return the .config files that exist in %WINDIR%\System32\inetsrv\config.

为此,我使用以下代码:

For this I am using the following code:

DirectoryInfo configFolder = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%WINDIR%") + @"\System32\inetsrv\");
FileInfo[] configFiles = configFolder.GetFiles("*.config");

这会将零个对象返回到configFiles.如果我使用其他文件夹(例如D:\ DropBox)可以正常工作!

This returns zero objects into configFiles. If I use another folder (say D:\DropBox) is works fine!

此代码曾经有效,但是有所更改?

This code used to work, has something changed??

此外,FileInfo fi = new FileInfo(Path.Combine(configPath, "applicationHost.config"));返回ok,但是fi.Length抛出FileNotFoundException.

Also, FileInfo fi = new FileInfo(Path.Combine(configPath, "applicationHost.config")); returns ok, but fi.Length throws FileNotFoundException.

似乎必须是权限,但是在代码运行时我看不到如何检查我是否具有权限!

Seems it must be permissions, but I can't see how to check if I have permissions when the code runs!

推荐答案

由于我不是开发人员,而且我只涉猎代码(主要是为自己编写管理工具),所以我想知道是否有人可以向我解释或指出我的观点.答案的正确位置?

As I am not a developer, and I only dabble with code (mostly writing admin tools for myself), I wonder if someone can explain or point me to the correct location for the answer?

基本上,我从别人的项目中获得了一些有效的代码,并将其复制到我自己的项目中.我很确定它以前曾奏过,但不能100%确定.当时我正在运行x86 Windows,但现在使用的是x64.

Basically, I had some code from someone else's project that worked, and copied it to my own project. I'm pretty sure it worked before, but can't be 100% certain. At that time I was running x86 Windows, but I'm now on x64.

旧代码仍然有效,所以我经历了复制设置并最终找到解决方案.

The old code still worked, so I went through copying the settings and eventually found the solution.

ProjectBuild properties中将平台目标"设置为Any CPU(来自x86)使它可以工作.将其设置为x64也可以,但是我认为这是一些安全性.

Setting "Platform Target" in the Project's Build properties to Any CPU (from x86) made it work. Setting it to x64 also worked, but I figure it is some security thing.

无论如何,问题已解决!感谢您的所有建议!

Anyway, problem solved! Thanks for all your suggestions!

这篇关于DirectoryInfo.GetFiles方法不返回任何文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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