如何访问“文档和设置"文件夹? [英] How can I access the "Documents and Settings" folder?
问题描述
我在VS 2010中使用C#.NET4.
I'm using C# .NET 4 with VS 2010.
遍历某些路径时,我正在运行以下行:
When Iterating over some paths, I'm running this line:
files = Directory.GetFiles(path, searchPattern);
当路径为文档和设置"文件夹时,出现异常.我该如何访问?而且,我不想尝试跳过该文件夹.我希望能够以某种方式访问它.
I get an exception when the path is the documents and settings folder. How can I access it? And no, I don't want to skip the folder with a try and catch. I want to be able to access it somehow.
我有一个后续问题.正如我告诉您的那样,我正在遍历所有路径.有没有一种方法可以使用 Environment.GetFolderPath
,但是可以根据我当前正在检查的路径以某种方式确定正确的特殊文件夹?
I got a follow up question. As I told you, I'm iterating over the paths. Is there a way to use Environment.GetFolderPath
but somehow idetifying the correct speical folder according to the path I'm currently checking?
推荐答案
您必须像这样使用
var mydocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
要访问 MyDocuments
文件夹.
这篇关于如何访问“文档和设置"文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!