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 Mike Lewis 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 based on the Date

Status
Not open for further replies.

RNF0528

MIS
Apr 4, 2006
115
US
I am tring to copy a file based on the date it was modifed\created?

The Path is:

C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data

Any ides the best way to attach this??

 
Try this.....

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 = InputBox("Date", "DATE", Date) 
strShare = "\\MyNewServer\MyBigShare\"

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, True
        Wscript.Echo strFile.Name & ", Mod-Date: " & objFile.DateLastModified & ", copied to " & strShare
    End If
    Set objFile = Nothing
Next


Wscript.Quit

Regards
 
If wanted to change the name of the file to Backup.log

How would I do that?
 
Just add this row instead :

fso.CopyFile strFile, strShare & "\Backup.log", True


Regards
 
I too am trying to use this script as it would be very helpful. However, I'm getting a Permission Denied on line 25. For testing I'm trying to copy the contents (based on date) of c:\temp to c:\temp2 but get this error. Any thoughts?

Thanks,
stan
 
Does the C:\Temp2 folder exist?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Please post the actual code that you are running.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Here is the code:



Option Explicit

CONST PATH = "C:\Temp\"

dim strDate_2_Copy
dim strShare
dim fso
dim objFolder
dim colFiles
dim objFile
dim strFile

Set fso = CreateObject("Scripting.FileSystemObject")

strDate_2_Copy = InputBox("Date of reports to send to LaserArc", "DATE", Date)
'strShare = "\\MyNewServer\MyBigShare\"
strShare = "c:\temp2"

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, True
Wscript.Echo strFile.Name & ", Mod-Date: " & objFile.DateLastModified & ", copied to " & strShare
End If
Set objFile = Nothing
Next



'Create Text File, or Append to Existing Log



Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\temp\copytolaserarclog.txt" , ForAppending, True)
objTextFile.WriteLine "Copy Completed " & Month(Now) & "_" & Day(Now) & "_" & Year(Now)
objTextFile.WriteLine "*******************************"

Wscript.Echo "Done"


Wscript.Quit



and I get a this error:

Script: path to .vbs
Line: 30
Char: 5
Error: Permission denied
Code: 800A0046
Source: MS VBScript runtime error




 
You may try this:
strShare = "c:\temp2[!]\[/!]"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
also, do you have rights on "\\MyNewServer\MyBigShare\"?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top