Wednesday, May 30, 2007

Adding a DateTimeStamp to a file

' Get the current Date Time and remove illegal chars
Dim strDTStamp As String = Format(Date.Now, "yyyyMMddHHmmss")

' This is the file we want to rename
Dim of As String = "C:\Myfile.txt"

' Insert DTStamp into the old name
Dim nf As String = of.Replace(".", strDTStamp & ".")

' Moving the file is like renaming it
System.IO.File.Move(of, nf)

No comments: