fravizza
07-08-2005, 07:42 PM
Hello. I'm a complete newbie at VBScript. I've been pulling my hair out trying to write a simple script to manage my database.
What I want to do is search for files with this the following dated format %50708%% and then copy those files from with the same date string into their own directory. I've attempted to do this copying canned sample code on Microsoft's website. I've been able to copy files, search for files but I'm unable to make a program that will loop and do it for all files in a date table. I hope my errors are simple and can be easily corrected.
Here is the code below. I'd appreciate any direction.
'Search Function
'Date Table
Dim Date(9)
Date(1) = 50331
Date(2) = 50318
Date(3) = 50630
Date(4) = 50629
Date(5) = 50701
Date(6) = 50616
Date(7) = 50617
Date(8) = 50621
Date(9) = 50630 '15
Dim MyString(9)
For n = 1 To 9
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where FileName Like '%' & Date_String & '%%' ")
For Each objFile in colFiles
objFSO.CopyFile objFile.Name , "C:\Documents and Settings\ravizza2\My Documents\OSL\Sort\50318\", OverwriteExisting
Next
Next
What I want to do is search for files with this the following dated format %50708%% and then copy those files from with the same date string into their own directory. I've attempted to do this copying canned sample code on Microsoft's website. I've been able to copy files, search for files but I'm unable to make a program that will loop and do it for all files in a date table. I hope my errors are simple and can be easily corrected.
Here is the code below. I'd appreciate any direction.
'Search Function
'Date Table
Dim Date(9)
Date(1) = 50331
Date(2) = 50318
Date(3) = 50630
Date(4) = 50629
Date(5) = 50701
Date(6) = 50616
Date(7) = 50617
Date(8) = 50621
Date(9) = 50630 '15
Dim MyString(9)
For n = 1 To 9
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where FileName Like '%' & Date_String & '%%' ")
For Each objFile in colFiles
objFSO.CopyFile objFile.Name , "C:\Documents and Settings\ravizza2\My Documents\OSL\Sort\50318\", OverwriteExisting
Next
Next