Reputation: 455
based off of what Microsoft tells me here: http://msdn.microsoft.com/en-us/library/xbfwysex(v=vs.84).aspx
this script should work
Sub Copy_Folder()
FileSystemObject.CopyFolder "C:\Testing\Test\", "C:\Testing\Test" & "_" & Format(Now, "yyyy-mm-dd")
End Sub
while playing around, I did receive some errors, which tells me the script is running. however, this runs w/o error, yet it just doesnt work. maybe its the date concatenation, so i comment out and just rename the folder to Tests (plural), it too runs w/o error yet doesnt do what it is supposed to. I've even moved the folder out of c:\Testing to the root of c, nope. sorry, this is noob but I dont get it.
Upvotes: 0
Views: 58
Reputation: 16311
As I mentioned in my comment, you can't use Format()
. Also, if you don't need the time, use Date
instead of Now
. Here's a VBScript alternative.
' Global scope...
Dim FileSystemObject
' Somewhere along the way...
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
' Your function...
Sub Copy_Folder()
Dim strDate
strDate = Year(Date) & "-" & Right("0" & Month(Date), 2) & "-" & Right("0" & Day(Date), 2)
FileSystemObject.CopyFolder "C:\Testing\Test\", "C:\Testing\Test" & "_" & strDate
End Sub
Finally, your code above should have returned an error. Make sure you're not using On Error Resume Next
anywhere in your code. It's almost never a good idea, especially for beginners or when debugging.
Upvotes: 2