This should do what you are looking for. it looks to see if the folder has already been copied, if it doesn't already exist, it copies it.
_____________________________
"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
Cheater! That's a 3rd party app! yer only allowed to use vbscript!
_____________________________
"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
If you really MUST check the time/date stamp ont he files, you can use this script:
It will only copy files that are newer than the last copy time. It *should* work, but is only aircode at this time, haven't tested it yet.
_____________________________
"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
First take this Code written by Digital ***************************************************************************************** Dim sOriginFolder, sDestinationFolder, sFile, oFSO Set oFSO = CreateObject("Scripting.FileSystemObject") sOriginFolder = "c:\tp" sDestinationFolder = "c:\tp2" For Each sFile In oFSO.GetFolder(sOriginFolder).Files If Not oFSO.FileExists(sDestinationFolder & "\" & oFSO.GetFileName(sFile)) Then oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True WScript.Echo "Copying : " & Chr(34) & oFSO.GetFileName(sFile) & Chr(34) & " to " & sDestinationFolder End If Next ***************************************************************************************** yes this works and logic is also simple check the file in folder B if its not there then copy to that folder.
But Assume i have 1500 files in floder A and each day its growing the file count...personaly i don't feel its a wise idea to go with that code
Thats why i thought go with Timestamp logic...just wanna check any new file come in last one hour
Just a note... either way you are going to be checking each file in the folder.
If we are throwing around 3rd party app suggestions, I would suggest ViceVersa Pro. It will run, and then monitor the folder. If there is a file added, it will then copy that file to the other folder immediately.
_____________________________
"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
Posts: 222
Score: 0
Joined: 11/12/2006
From: UK
Status: offline
Just a though... but you could approach this from a different angle..
Instead of looking at time stamps ect, you could use file attributes... (native since DOS 2.0!!) When you create a file it is automaticaly created with the archive attribute selected. it is also re-added when ever a file is ammended or changed. you could use XCOPY to copy all files with the archive attribute set, and then remove the attribute (untill it is next changed) as part of the XCOPY process..
or if you wish to use vbscript... you can read and write to this attribute like so..
to write back to the atribute wyou would use...
file.attributes = file.attributes + 32 '<------ to set archive on
file.attributes = file.attributes - 32 '<------ to set archive off
not sure if it helps... but thats the way i'd probably try and approach it.
< Message edited by Parabellum -- 2/14/2007 8:39:34 AM >
Posts: 222
Score: 0
Joined: 11/12/2006
From: UK
Status: offline
infact forget the xcopy...
I'm feeling generous... here's a complete working version (tested), Based on the code i pasted above. you could set this script to run as a sheduled task every hour for example..
Dont forget to change the variables (i high-lighted them in red)
Option Explicit Dim objFSO, strSourceFolder, strDestFolder, strExclusion, strPrompt Set objFSO = CreateObject("Scripting.FileSystemObject") strSourceFolder = "c:\MyImportantData" strDestFolder = "c:\MyBackupFolder" strExclusion = "" ' Example: zip,vbs,exe,js,rar If IsNoData(strExclusion) Then strExclusion = "" 'Make sure it is blank. 'Call function that will copy folder structure as well as files in it. CopyFolderStructure strSourceFolder, strDestFolder, strExclusion Function CopyFolderStructure(strSource, strDestination, strExcludedExt) Const OVER_WRITE_FILES = True Dim objDir, objFolder, objFiles, strCurExt, intX, arrExt, blnExclude
'Connect to the current directory in strSource. Set objDir = objFSO.GetFolder(strSource)
'If destination folder doesn't exist, create it. If Not objFSO.FolderExists(strDestination) Then objFSO.CreateFolder(strDestination) End If
'If current folder doesn't exist under destination folder, create it. If Not objFSO.FolderExists(strDestination & "\" & objDir.Name) Then objFSO.CreateFolder(strDestination & "\" & objDir.Name) End If 'Validate if there is something in strExcludedExt. If Not IsNoData(strExcludedExt) Then 'If yes, transfer content from strExcludedExt in an array. arrExt = Split(strExcludedExt, ",") blnExclude = False 'Intialize to False blnExclude End If 'Loop through all files in current folder if any and copy all files in destination folder 'except for excluded extension if any in strExcludedExt. For Each objFiles In objFSO.GetFolder(strSource).Files If objFiles.attributes and 32 Then ' Check if the Archive Atrtibut Is set 'If there is exclusion, will compare if current extension file is excluded or not. If Not IsNoData(strExcludedExt) Then strCurExt = objFSO.GetExtensionName(objFiles.Name) 'Take current extension. 'Loop through the array to find if current extension has to be copied or not. For intX = 0 To UBound(arrExt) If LCase(strCurExt) = arrExt(intX) Then blnExclude = True 'If found, set to True blnExclude and exit for. Exit For Else blnExclude = False End If Next If Not blnExclude Then 'If blnExclude is True, current file will not be copied. objFSO.CopyFile strSource & "\" & objFiles.Name, strDestination & "\" & objDir.Name & "\" & objFiles.Name, OVER_WRITE_FILES objFiles.attributes = objFiles.attributes - 32 End If Else 'If no exclusion, copy everything in all folders/subfolders objFSO.CopyFile strSource & "\" & objFiles.Name, strDestination & "\" & objDir.Name & "\" & objFiles.Name, OVER_WRITE_FILES objFiles.attributes = objFiles.attributes - 32 End If End If Next ' If there is subfolder(s) under current folder in strPath, Call ' recursively this sub until there is no other subfolder(s) For Each objFolder In objFSO.GetFolder(strSource).SubFolders CopyFolderStructure objFolder.Path, strDestination & "\" & objDir.Name, strExcludedExt Next End Function Function IsNoData(varVal2Check) 'Verify if varVal2Check contain something. On Error Resume Next If IsNull(varVal2Check) Or IsEmpty(varVal2Check) Then IsNoData = True Else If IsDate(varVal2Check) Then IsNoData = False Elseif varVal2Check = "" Then IsNoData = True ElseIf Not IsObject(varVal2Check) Then IsNoData = False Else IsNoData = False End If End If End Function
< Message edited by Parabellum -- 2/15/2007 5:06:43 AM >
After so many thought i like to go with WMI...here is the code
'========================================================================== ' NAME: WMI_Copy_Prod2Blade.vbs ' AUTHOR:Your Name ' DATE : ' COMMENT: This Code copy files from Production folder to Blade folder,whenever new file is added in to Production Foler ''========================================================================== strComputer = "." 'Local Computer running on this script set objFSO = CreateObject("Scripting.FileSystemObject") Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""c:\\\\scripts""'") 'Monitor the files in Script Folder in C dirve Do Set objLatestEvent = colMonitoredEvents.NextEvent ' WScript.Echo objLatestEvent.TargetInstance.PartComponent 'Copying the files to Destination Folder strFile = objLatestEvent.TargetInstance.PartComponent strFile = Replace(Mid(strFile, InStr(strFile, Chr(34)) + 1), "\\", "\") strFile = Left(strFile, Len(strFile) - 1) objFSO.CopyFile strFile, "C:\FolderB\"
The simplicity of (code below) is brilliant, i have removed the dialogue box to appear after every file, only at the end. Is it possible to only include sertain file extensions. All the code has been excluding file extensions. For work got a folder that has lots of files but only two extensions need copying. In addition, is it possible to cut instead of copy.
Dim sOriginFolder, sDestinationFolder, sFile, oFSO Set oFSO = CreateObject("Scripting.FileSystemObject") sOriginFolder = "c:\test" sDestinationFolder = "c:\test2" For Each sFile In oFSO.GetFolder(sOriginFolder).Files If Not oFSO.FileExists(sDestinationFolder & "\" & oFSO.GetFileName(sFile)) Then oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True End if next WScript.Echo "Copying : All the files have been copied to " & sDestinationFolder
< Message edited by maksim -- 2/22/2007 3:58:13 PM >
The simplicity of (code below) is brilliant, i have removed the dialogue box to appear after every file, only at the end. Is it possible to only include sertain file extensions. All the code has been excluding file extensions. For work got a folder that has lots of files but only two extensions need copying. In addition, is it possible to cut instead of copy.
Dim sOriginFolder, sDestinationFolder, sFile, oFSO Set oFSO = CreateObject("Scripting.FileSystemObject") sOriginFolder = "c:\test" sDestinationFolder = "c:\test2" For Each sFile In oFSO.GetFolder(sOriginFolder).Files If Not oFSO.FileExists(sDestinationFolder & "\" & oFSO.GetFileName(sFile)) Then oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True End if next WScript.Echo "Copying : All the files have been copied to " & sDestinationFolder
Thanks for the kind words.
To only check for certain extensions, use this code. It also has a boolean to select whether to move or copy the file:
_____________________________
"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers
"Would you like to touch my monkey?" - Dieter (Mike Meyers)