C#System.IO.File.Exists不能统一工作

C#System.IO.File.Exists不能统一工作,c#,windows,unity3d,system.io.file,C#,Windows,Unity3d,System.io.file,我试图在我的电脑上找到一个文件,这样我就可以将我的游戏登录数据存储在那个特定的文件上。我有一个包含路径的字符串 public string path = "C:/Users/DevelopVR/Documents"; //DevelopVR is my username 那么稍后我会说: if (System.IO.File.Exists(path)) { Debug.Log("Path exists on this computer"); } els

我试图在我的电脑上找到一个文件,这样我就可以将我的游戏登录数据存储在那个特定的文件上。我有一个包含路径的字符串

public string path = "C:/Users/DevelopVR/Documents";
//DevelopVR is my username
那么稍后我会说:

if (System.IO.File.Exists(path))
{
Debug.Log("Path exists on this computer");
}

else
{
Debug.LogWarning("Path does NOT exist on this computer");
}

我也尝试过替换以下内容:

else
{
Debug.LogWarning("Path does NOT exist on this computer");
}
为此:

else if (!System.IO.File.Exists(path))
{
Debug.LogWarning("Path does NOT exist on this computer");
}
但每次它都会记录错误。所以我不知道该怎么办。似乎其他人也有同样的问题。谢谢,如果你有答案的话。

“文档”不是一个真正的路径,它是指向Windows提供的“特殊文件夹”的方便链接

“文档”不是真正的路径,它是指向Windows提供的“特殊文件夹”的方便链接


文档
是一个目录,而不是文件,因此与其检查
文件
,不如检查
目录
,如:

if(File.Exists(path))
{
    // This path is a file
    ProcessFile(path);
}
else if(Directory.Exists(path))
{
    // This path is a directory
    ProcessDirectory(path);
}
请记住,如果要搜索文件
路径
的文件名和扩展名如下:

public string path = @"C:/Users/DevelopVR/Documents/MyFile.txt";

文档
是一个目录,而不是文件,因此与其检查
文件
,不如检查
目录
,如:

if(File.Exists(path))
{
    // This path is a file
    ProcessFile(path);
}
else if(Directory.Exists(path))
{
    // This path is a directory
    ProcessDirectory(path);
}
请记住,如果要搜索文件
路径
的文件名和扩展名如下:

public string path = @"C:/Users/DevelopVR/Documents/MyFile.txt";

尝试绝对路径,而不是简单的“文档”,使用“C:\Users\YourUsername\Documents”否。仍然输出“此计算机上不存在路径”请考虑AppData目录中的配置信息,而不是文档。@GraniteSOS但您正在尝试检查目录或文件?我正在尝试检查文件尝试绝对路径,而不是简单的“文档”,请使用“C:\Users\YourUsername\Documents”否。仍然输出“此计算机上不存在路径”请考虑AppData目录以获取配置信息,而不是文档。@GraniteSOS但您正在尝试检查目录或文件?我正在尝试检查文件我必须将存储在文件夹中的数据放在目录中。我必须将存储在文件夹中的数据放在文件夹中目录内。问题询问者指定的路径确实存在问题在我发布此答案后已被编辑问题询问者指定的路径确实存在问题在我发布此答案后已被编辑