Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable problem w/VBscript

Status
Not open for further replies.

bcmill

IS-IT--Management
Jul 3, 2001
1
US
I am trying to capture the system date and use it as the name of a new folder. I can't get the syntax right. I am trying to insert the date where I have placed the ?'s. Any help or ideas would be appreciated.

option explicit

'Variables
dim oCrntDate
dim oCrtFldr
dim oSource
dim oDest
Dim lfsObject
Dim lFileList
Dim lFolder
Dim lFile

oSource = "c:\Test\source"
oCrntDate = Date

'Create Folder
set oCrtFldr = CreateObject("Scripting.FileSystemObject")
set oDest = oCrtFldr.CreateFolder ("\\Server1\Test\?????")

'Copy Files
on error resume next
Set lfsObject = CreateObject("Scripting.FileSystemObject")
Set lFolder = lfsObject.GetFolder(oSource)
Set lFileList = lFolder.Files
For Each lFile in lFileList
lfsObject.CopyFile oSource & "\" & lFile.Name, oDest & "\" & lFile.Name
next
 
The reason why the script will not work is because the Date function returns "7/3/01" by default and the file system will not allow the "/" in a file name. I added a new variable

Dim newFolder

Set the value to the path and formated the date to remove the "/"

newFolder = "c:\test\" & formatdattime(oCrntDate, vbLongDate)

and then created the folder

set oDest = oCrtFldr.CreateFolder (newFolder)

and everything worked.

Hope This helps
RnK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top