【发布时间】:2023-03-29 15:12:01
【问题描述】:
好吧,假设我们有这个层次结构:ParentFolder > ChildFolder > Files
我想要检查 ParentFolder 是否存在,如果存在则获取 ChildFolder 中的文件。到目前为止我得到的是
string MainFolderPaths = Application.persistentDataPath + "/ParentFolder";
//Check existence of folder
if (Directory.Exists(MainFolderPaths))
{
msgText.text = "Folder exist";
//Returns the subdirectories in MainFolderPaths
MainFolderDirectory = Directory.GetDirectories(MainFolderPaths);
//Go through the folders that exist in the MainFolderDirectory
foreach(var folder in MainFolderDirectory)
{
//Get the files that are in each folder
string[] files = Directory.GetFiles(folders);
//Go through the files
foreach(string file in files)
{
//read text file here
}
}
}
else
{
msgText.text = "No folder found.";
}
我已经更新了代码。我想知道我在做什么是否正确?如果这是正确的,那么我可能是读取文件错误。
【问题讨论】:
-
好吧,你从来没有告诉过在哪里找到
ParentFolder。您的MainFolderPaths变量包含 relative 路径,而您从不说从哪里开始查找。 -
我实际上是在使用`Application.persistentDataPath`
-
你现在是。我发表评论时你还不是。
标签: file unity3d directory subdirectory