目录

一.目的

1.想知道:unity 判断路径是否存在或者文件夹是否存在

1.想实现的功能:某路径下,检查是否有名字为“1”-“20”名字的文件夹。

二.参考

1.Unity api

1.unity 判断路径是否存在或者文件夹是否存在

1.如何检查文件是否存在于unity android中?(How to check a file exist or not in unity android?)

1.Unity安卓配置文件:读和写

1.unity 通过代码查找一个文件夹下的所有文件

三.注意:Directory.Exists和File.Exists是有去别的,

1.经过多次测试:只能 Application.persistentDataPath  和File.Exists(str_filePath)只能发现指定类型的文件,而无法发现某名字的文件夹。

四.操作:完成:获取指定路径下面是否存在名字为“1”的文件夹。

1.可以获取指定路径下面是否存在名字为“1”的文件夹。

三.操作:完成:文件夹不存在就创建


一.目的

1.想知道:unity 判断路径是否存在或者文件夹是否存在

 

1.想实现的功能:某路径下,检查是否有名字为“1”-“20”名字的文件夹。

 

二.参考

1.Unity api

https://docs.unity3d.com/ScriptReference/Windows.Directory.html"

  • 总结:good:适合多看

 

1.unity 判断路径是否存在或者文件夹是否存在

  • 总结:good:判断指定路径内是否有指定文件夹-System.IO.Directory.Exists("路径")
  • 总结:good:判断指定路径内是否有指定文件- System.IO.File.Exists(“路径”)

 

  • 总结:下面是我自己操作:是成功的。

Android判断某个文件是否存在 android判断文件夹是否存在_资源文件

//测试:12:获取指定路径下面文件夹是否存在:待检测
        string tmpStr_fileName = "1";
        string str_filePath = Application.persistentDataPath + "/"+ "MyRecord" + "/"+ tmpStr_fileName;
        Debug.LogError("Unity xzy :检查的文件夹路径:" + str_filePath);

        //获取指定路径下面的所有资源文件  
        if (Directory.Exists(str_filePath))
        {
            Debug.LogError("Unity xzy :文件夹 1  已经存在:路径是" + str_filePath);
        }
        else
        {
            Debug.LogError("Unity xzy :文件夹 1  不存在:");
        }

        return tmpStr_fileName;

 

 

1.如何检查文件是否存在于unity android中?(How to check a file exist or not in unity android?)

https://www.it1352.com/1850161.html

  • 总结:失败

 

 

1.Unity安卓配置文件:读和写

  • 总结:good:可以实现

 

 

1.unity 通过代码查找一个文件夹下的所有文件

  • 总结:good:就是我所需要的;因为Application.persistentDataPath  和File.Exists(str_filePath)只能发现指定类型的文件,而无法发现某名字的文件夹。所以想通过查找所有文件的方法,判断这个文件夹里面是否有指定文件。

 

  • 总结:Name找到文件的名字。
  • 总结:FullName找到文件整个路径
  • 总结:DirectoryName找到文件所在的绝对路径。

Android判断某个文件是否存在 android判断文件夹是否存在_配置文件_02

//测试:10:获取指定路径下面文件夹是否存在:成功
        string tmpStr_fileName = "";
        string str_filePath = Application.persistentDataPath + "/";
        Debug.LogError("Unity xzy :检查的文件夹路径:" + str_filePath);

        //获取指定路径下面的所有资源文件  
        if (Directory.Exists(str_filePath))
        {
            DirectoryInfo direction = new DirectoryInfo(str_filePath);
            FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);

            Debug.Log(files.Length);

            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Name.EndsWith(".meta"))
                {
                    continue;
                }
                Debug.LogError("Unity xzy :Name:" + files[i].Name);
                Debug.LogError("Unity xzy :FullName:" + files[i].FullName);
                Debug.LogError("Unity xzy :DirectoryName:" + files[i].DirectoryName);
            }
        }

 

三.注意:Directory.Exists和File.Exists是有去别的,

1.经过多次测试:只能 Application.persistentDataPath  和File.Exists(str_filePath)只能发现指定类型的文件,而无法发现某名字的文件夹。

Android判断某个文件是否存在 android判断文件夹是否存在_android_03

 

 

四.操作:完成:获取指定路径下面是否存在名字为“1”的文件夹。

1.可以获取指定路径下面是否存在名字为“1”的文件夹。

 

Android判断某个文件是否存在 android判断文件夹是否存在_android_04

//测试:12:获取指定路径下面文件夹是否存在:待检测
        string tmpStr_fileName = "1";
        string str_filePath = Application.persistentDataPath + "/"+ "MyRecord" + "/"+ tmpStr_fileName;
        Debug.LogError("Unity xzy :检查的文件夹路径:" + str_filePath);

        //获取指定路径下面的所有资源文件  
        if (Directory.Exists(str_filePath))
        {
            Debug.LogError("Unity xzy :文件夹 1  已经存在:路径是" + str_filePath);
        }
        else
        {
            Debug.LogError("Unity xzy :文件夹 1  不存在:");
        }

        return tmpStr_fileName;

 

三.操作:完成:文件夹不存在就创建

Android判断某个文件是否存在 android判断文件夹是否存在_资源文件_05

测试:12:获取指定路径下面文件夹是否存在:完成
        string tmpStr_fileName = "";

        //TODO:第 1 步:检查是否存在0-19文件夹:完成
        for (int i = 0; i <nCreateRecordDirectoryNum; i++)
        {
            tmpStr_fileName = i.ToString();
            string str_filePath = Application.persistentDataPath + "/" + strRecordFileName+ "/" + tmpStr_fileName;
            Debug.LogError("Unity xzy :检查的文件夹路径:" + str_filePath);

            //获取指定路径下面的所有资源文件  
            if (Directory.Exists(str_filePath))
            {
                Debug.LogError("Unity xzy :文件夹 :"+i+":已经存在:路径是" + str_filePath);
            }
            else
            {
                Debug.LogError("Unity xzy :文件夹 :" + i + ":不存在,然后创建" );

                //TODO:第 2 步:0-19哪个文件夹不存在,创建此文件夹,并且从此文件夹里面开始添加录制视频
                Directory.CreateDirectory(str_filePath);
            }
        }