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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy a file with vbs (by modified, name)

Status
Not open for further replies.

RNF0528

MIS
Joined
Apr 4, 2006
Messages
115
Location
US
Need to adjust Script to copy a specific file name.

There are many files in the folder.
I need to copy the ones that start with a name of "Batch*.html" and have been modified today.

I tried to add a \batch* to the CONST Path but it will not go.

Here is the code.
------------------------------------------------------------
Option Explicit

CONST PATH = "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"

Dim strDate_2_Copy, strShare
Dim fso, objFolder, colFiles, objFile, strFile

Set fso = CreateObject("Scripting.FileSystemObject")

strDate_2_Copy = Date
strShare = "C:\EmailReport\"

If fso.FolderExists(PATH) Then
Set objFolder = fso.GetFolder(PATH)
Set colFiles = objFolder.Files
Else
Wscript.Echo "Can't find the " & PATH & " folder"
Wscript.Quit
End if

For Each strFile in colFiles
Set objFile = fso.GetFile(strFile)
If DateDiff("d", objFile.DateLastModified, strDate_2_Copy) = 0 Then
fso.CopyFile strFile, strShare & "\GPSBackup.log" , True
' Wscript.Echo strFile.Name & ", Mod-Date: " & objFile.DateLastModified & ", copied to " & strShare
End If
Set objFile = Nothing
Next


Wscript.Quit
------------------------------------------------------------

 
You may try this:
For Each strFile in colFiles
If Int(strFile.DateLastModified) = Int(Date) _
And Left(LCase(strFile.Name,5)="batch") _
And Right(LCase(strFile.Name,5)=".html" Then
fso.CopyFile strFile, strShare & "\GPSBackup.log" , True
Exit For
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Will this allow me to use the * wilcard?

The reason i ask is becuase batch is just the begining of the filename?

ie. batch-12-6543-JUL-2006
 
Error Message:

Wrong number of arguments or invalid property Assignment:'LCase"

Thanks Agian for the help!!
 
OOps, sorry for the typos :~/
For Each strFile in colFiles
If Int(strFile.DateLastModified) = Int(Date) _
And Left(LCase(strFile.Name),5)="batch" _
And Right(LCase(strFile.Name),5)=".html" Then
fso.CopyFile strFile, strShare & "\GPSBackup.log" , True
Exit For
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top