/*
* BLLib.IO.FileUtil
* Andy Tidball
*
* Project: Black Lightning General Library
* Copyright: GNU General Public License
*/
using System;
using System.IO;
namespace BLLib.IO {
///
/// A static utility class for working with files. Often provides additional functionality for System.IO.File.
///
public static class FileUtil {
///
/// Checks if a given file exists.
///
/// The filename to check for existance.
/// Whether or not the search should be case-sensitive.
/// True if the given file exists, false if it does not.
public static bool Exists(string Filename, bool CaseSensitive) {
// first, check if this file exists not counting cast
bool FileExists = File.Exists(Filename);
// if they don't care about case, just return what we already know
if (!CaseSensitive) {
return FileExists;
}
// if this file didn't exist, just return now
if (!FileExists) {
return false;
}
// to check the case, we're going to get a file list from the directory to compare against
FileInfo Info = new FileInfo(Filename);
FileInfo[] Files = Info.Directory.GetFiles(Filename, SearchOption.TopDirectoryOnly);
// since we specified the filename as a pattern, we should have gotten exactly that one file returned
System.Diagnostics.Debug.Assert(Files.Length == 1);
// check to make sure the one filename received matches the entered filename, case-sensitively
return (Filename == Files[0].Name);
}
}
}