DeadByDaylightBackup.Utility/FileUtility.cs
/// <summary>
/// In a path, get the file with the specified extesion
/// </summary>
/// <param name="path">Path to search</param>
/// <param name="extension">desired extension</param>
/// <returns>Filepath</returns>
In a path, get the file with the specified extesion
In a path get the file with the specified extesion
public static string GetFileWithExtension(string path, string extension)
        {
            path = path.Trim();
            extension = extension.Trim();
            if (!extension.StartsWith(".")) extension = "." + extension;
            if (FileExists(path) && path.EndsWith(extension, StringComparison.OrdinalIgnoreCase))
            {
                return path;
            }
            if (Directory.Exists(path))
            {
                return Directory.GetFiles(path).Where(x => x.EndsWith(extension, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            }
            else { throw new IOException("Path not found: " + path); }
        }
public static string GetFileWithExtension ( string path , string extension ) { path = path . Trim ( ) ; extension = extension . Trim ( ) ; if ( ! extension . StartsWith ( " " ) ) extension = " " + extension ; if ( FileExists ( path ) && path . EndsWith ( extension , StringComparison . OrdinalIgnoreCase ) ) { return path ; } if ( Directory . Exists ( path ) ) { return Directory . GetFiles ( path ) . Where ( x => x . EndsWith ( extension , StringComparison . OrdinalIgnoreCase ) ) . FirstOrDefault ( ) ; } else { throw new IOException ( " " + path ) ; } }
In a path, get the file with the specified extesion
In a path get the file with the specified extesion
None
path
string
Path to search
Path to search
extension
string
None