bigMre bigMre - 1 month ago 22
Vb.net Question

VB Rename Folder to DATE_TIME

I want to rename a folder to the current date and time using VB.NET

Dim thisDate As Date
thisDate = Today
My.Computer.FileSystem.RenameDirectory(Destination, "Backup_" & Today)

Answer

use this:

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    If String.IsNullOrEmpty(Source) OrElse String.IsNullOrEmpty(Destination) Then
        MsgBox("Source and Destination cant be empty")
        Exit Sub
    End If

    My.Computer.FileSystem.CopyDirectory(Source, Destination, True)

    Dim DestinationBackup As String = "C:\temp"
    Dim NewDir As String = System.IO.Path.Combine(DestinationBackup, "Backup_" & DateTime.Now.ToString("yyyyMMddHHmmssfffff"))
    If System.IO.Directory.Exists(NewDir) Then
        System.IO.Directory.Delete(NewDir, True)
    End If

    System.IO.Directory.Move(Destination, NewDir)

End Sub
Comments