如何访问“文档和设置"?文件夹? [英] How can I access the "Documents and Settings" folder?
问题描述
我在 VS 2010 中使用 C# .NET 4.
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屋!