using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace StarEngine.Ruby
{
    internal static class PathExtensions
    {
        /// <summary>
        /// 拡張子の省略を考慮して、フルパスを取得します。
        /// </summary>
        /// <param name="path">パス。</param>
        /// <returns>フルパス。</returns>
        public static string GetFullPathAndExtension(string path)
        {
            path = Path.GetFullPath(path);
            if (File.Exists(path))
                return path;

            string dir = Path.GetDirectoryName(path);
            if (!Directory.Exists(dir))
                return path;

            string[] files = Directory.GetFiles(dir, Path.GetFileName(path) + ".*");
            if (files.Length == 0)
                return path;

            Array.Sort<string>(files);
            return files[0];
        }
    }
}
