I want to use the current date and time to cr

June 9, 2010 at 09:38:13
Specs: Windows XP
I have a test script below, using date and time stripped of illegal characters to create a folder. Need to copy a set backup file to the variable folder name. Cannot find how to set directory with a variable?? Test Script below:

MyDate = Now
Dim dir
dir = (Replace(Replace(MyDate, "/", ""), ":", ""))
Wscript.Echo dir
Wscript.Echo MyDate
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder (Replace(Replace(MyDate, "/", ""), ":", ""))
Wscript.Echo objFolder
Dim cath
cath = Directory.GetCurrentDirectory()
Wscript.Echo cath
Dim WoShell
set WoShell = CreateObject("WScript.Shell")
Wscript.Echo WoShell.currentdirectory
objShell.CurrentDirectory = objFolder & "\"


See More: I want to use the current date and time to cr

Report •


#1
June 9, 2010 at 11:14:32
Cannot find how to set directory with a variable?
Set what to a directory?

Report •

#2
June 9, 2010 at 11:20:48
I have the script creating a folder based on the variable MyDate which is derived from the command NOW. I want to move a backup file that gets overwrote every night to this unique folder so I can keep history. I do not see how to use the variable MyDate in the command line to copy the file to this unique folder since it is variable and changes everynight? And thanks for the fast reply!!! I've spent hours on this and no luck.

Report •

#3
June 9, 2010 at 12:00:12
objfso.copyfile("\logfile",dir)

none of my business, but i would make just one directory
and copy the logfiles into that directory with date for filename.
that way you can view them all in one place without having
to do a bunch of CD.


Report •

Related Solutions

#4
June 9, 2010 at 12:44:17
I don't know how to do it in VBS but here is how you can do it with a batch script....

@echo off
Set ToFolder=%Date:~-4,4%-%Date:~-10,2%-%Date:~-7,2%
Copy %1 %2\%ToFolder%

Hope it helps.


Report •

#5
June 9, 2010 at 20:46:27
Pretty much what nbrane said.
objFSO.CopyFile("file", objFolder & "\")


Report •

#6
June 10, 2010 at 08:43:16
Thanks to everybody. I actually combined some suggestions, needed the trailing backslash and the over write code.

Works great! And thanks again! Great forum.


Report •


Ask Question