mmFile

OakLeaf.MM.Main.mmFile

Extends the functionality of the .NET File class

CreateUniqueFileName()

  • Creates a unique file name for the specified directory and file. If the file already exists in the specified directory, this method attempts to create a unique file by adding successive integers to the file stem (filename1.ext, filename2.ext, etc.)

    public static string CreateUniqueFileName(string directory, string fileName)
    Public Shared Function CreateUniqueFileName(directory As String, fileName As String) As String

    Example:

    In C#:

    string DestFileName = mmFile.CreateUniqueFileName("c:\Temp", "MyFile.txt");

    In VB .NET:

    Dim DestFileName As String = mmFile.CreateUniqueFileName("c:\Temp", "MyFile.txt")

StringToFile()

  • Writes the specified string to the specified file. If the file exists, it is deleted and recreated

    public static void StringToFile(string expression, string fileName)
    Public Shared Sub StringToFile(expression As String, fileName As String)

  • Writes the specified string to the specified file. If the additive parameter is true, the string is appended to the file, if false, any existing file is deleted, then recreated

    public static void StringToFile(string expression, string fileName, bool additive)
    Public Shared Sub StringToFile(expression As String, fileName As String, additive As Boolean)

    Example:

    In C#:

    mmString.Proper("Hello .NET World", "Test.txt");

    In VB .NET:

    mmString.Proper("Hello .NET World", "Test.txt")

CompareLastModifiedDates()

  • Compares the LastWriteTime property of the FileInfo objects.
    This method can be used to sort an array of FileInfo objects by LastWriteTime.

    public static int CompareLastWriteTime(FileInfo fileInfo1, FileInfo fileInfo2)

    Public Shared Function CompareLastModifiedDates(fileInfo1 As FileInfo, fileInfo2 As FileInfo) As Integer

    Example:

    In C#:

    DirectoryInfo DirInfo = new DirectoryInfo(@"C:\");
    FileInfo[] FileInfoList = DirInfo.GetFiles();
    Array.Sort(FileInfoList, mmFile.CompareLastWriteTime);

    In VB .NET:

    DirectoryInfo DirInfo = new DirectoryInfo("C:\");
    Dim FileInfoList As FileInfo() = DirInfo.GetFiles()
    Array.Sort(FileInfoList, mmFile.CompareLastWriteTime)


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/27/18
Comment or report problem with topic