hsingh1981
Programmer
Hi all,
I managed to move all files with the extension *.mdi What i would like to do is to add a datestamp at the end of each file whilst i'm moving the files over. Can this be done? Preferably before "." extension name but after the filename
I managed to move all files with the extension *.mdi What i would like to do is to add a datestamp at the end of each file whilst i'm moving the files over. Can this be done? Preferably before "." extension name but after the filename
Code:
Sub MoveFilesFolder2Folder()
On Error GoTo EH
Dim FSO
Dim dateStamp As Date
dateStamp = Format(Date, "_yyyy_mm_dd")
Set FSO = CreateObject("Scripting.FileSystemObject")
'On Error Resume Next
If Not FSO.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
ElseIf Not FSO.FolderExists(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid Destination"
Else
FSO.MoveFile (sfol & "\*.mdi"), (dfol & dateStamp) ' Change "\*.*" to "\*.mdi" to move mdi Files only
End If
EH:
If Err.Number = 58 Then '<----- Special handling for File Exists
MsgBox "File Exists"
Else
MsgBox "Error " & Err.Number & ": " & Err.Description '<---- General error handling
End If
If Err.Number = 53 Then MsgBox "File not found"
End Sub