天天看點

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;
        }
    }