天天看点

C#获取指定文件夹下所有文件夹名称

public static string[] GetFilePath(string path)
    {
        if (Directory.Exists(path))
        {
            //文件路径
            string[] dir = Directory.GetDirectories(path);
            //文件名
            string[] names = new string[dir.Length];
            for (int i = 0; i < dir.Length; i++)
            {
                //赋值文件命名
                names[i] = Path.GetFileName(dir[i]);
            }
            return names;
        }
        else
        {
            Debug.LogError("未找到路径");
            return null;
        }
    }