Help Copying a folder based on modified date

October 7, 2009 at 09:10:13
Specs: Windows XP
Hi i Need help to make this script work. It supposed to copy a folder from documents and settings based on the date it was modified.

So what i want it ti do is check every folder in documents and setting for the last 14 days if its within that period copy the folder with the name and sub folders to a specified directory.

Thanks in advance for you help


dim FileSystemObject
dim oNet
dim fso
dim oFolder
Dim objNetwork
Dim strDriveLetter, strRemotePath
strDriveLetter = "Q:"
strRemotePath = "\\servername"
Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("SYSTEM")
Set filesys = CreateObject("Scripting.FileSystemObject")
StrUsername = wshShell.ExpandEnvironmentStrings("%username%")
Set objNetwork = CreateObject("WScript.Network")
set strComputer=WScript.CreateObject("WScript.Network")
Set fso = createobject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(Path1)

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

filesys.CopyFolder "c:\program files\notes", "Q:" & strComputer

filesys.CopyFolder "c:\program files\Personal Communications\Private", "Q:" & strComputer

For Each objSubfolder in colSubfolders
If Date(objSubfolder.DateLastModified) < Date(Now() - NumberOfDaysOld) Then
End If


See More: Help Copying a folder based on modified date

Report •

October 12, 2009 at 19:02:26
i got this to work:
'----- all your stuff here
''------ at bottom:

set x=fso.Getfolder(".")
for each folder in x.subfolders
dd1= folder.DateLastModified
''-------'this is just a diagnostic
wscript.echo "dd1 ",dd1
wscript.echo "dd2 ",dd2
wscript.echo "diff ",diff
''------'here is where you would put the delete
if diff>7 then
wscript.echo "delete folder here..."
End If


the date subtraction actually seemed to work, i tried it out
on a file that was from 1/20/08 and it came up with 630
(ran on 10/12/09). I haven't worked much with scripting, so
it took a lot of trial & sin-tax error before even getting it
to attempt to run. If you know of a good place to get all
the wscript commands and a lot of the objects documentation
(like fso: method and property names, let me know).

Report •

October 12, 2009 at 19:30:46
If you're looking for help with writing Scripts, I would start by looking here.

Report •

October 12, 2009 at 20:25:54
The following will look in your Documents and settings folder for any folders that have been modified in the last 14 day's and then copy the folder and it's contents. You need to set the destionation of where it will be copied by changing it from "C:\Backup\" to the directory that you are trying to copy to.

Option Explicit

Dim objFSO, objFolder, colSubFolders, objSubFolder
Const OverWriteFiles = True

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Documents and Settings")
Set colSubfolders = objFolder.Subfolders

For Each objSubfolder in colSubfolders
if (DateDiff("d",Date,objSubFolder.DateLastModified)) >= -14 then
'You need to set what you want for the Destination folder
objFSO.CopyFolder objSubFolder, "c:\Backup\", OverWriteFiles
End If

Report •

Related Solutions

October 13, 2009 at 02:47:35
thanks qt..

Report •

Ask Question