"Jonathan Duane" <> wrote in message
news:1063e386-7924-47ec-bb18-...
> Hi,
>
> I am new enough to VB and so far i have been lucky enough to get code
> from some really helpful guys at Experts Exchange the script i have so
> far is
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> SOURCE = "C:\jtest"
> TARGET1 = "c:\jtest1"
> TARGET2 = "c:\jtest2"
> TARGET3 = "c:\jtest3"
>
> Main
>
> Sub Main
> 'Verify if source folder exists
> If Not (objFSO.FolderExists(SOURCE)) Then
> MsgBox "Source Folder Missing"
> Else
> 'Run the moveFiles function
> moveFiles Source, Target1
> moveFiles Source, Target2
> moveFiles Source, Target3
> 'Delete the TARGET folder (and contents)
> objFSO.DeleteFolder SOURCE,Force
> 'Recreate TARGET folder
> objFSO.CreateFolder SOURCE
> 'Wait time before checking SOURCE again
> WScript.Sleep 5000
> Main
> End If
> End Sub
>
> Function moveFiles(copysource, ctarget)
> 'Create target directory if does not exist
> If Not (objFSO.FolderExists(ctarget)) Then
> objFSO.CreateFolder(ctarget)
> End If
> 'Copy files from SOURCE to TARGET
> objFSO.CopyFolder copysource, ctarget
> End Function 'replicateFolders
>
>
> But as the guys have pointed out when files come into the souce folder
> and are bigger than 1 oe 2 mbs the script will grab them and them in
> when tey havent fully transferred, is there anyway of putting a line
> into the code where it says wait til the file hasnt been accessed for
> x amount of seconds???
If this is the code that the ExpertsExchange guys propose then the
subscription you paid them is a waste of money. Here is why:
- The line
objFSO.DeleteFolder SOURCE,Force
must read
objFSO.DeleteFolder SOURCE, true
or perhaps
objFSO.DeleteFolder SOURCE, false
- You have the lines
objFSO.DeleteFolder SOURCE,Force
objFSO.CreateFolder SOURCE
and elsewhere
If Not (objFSO.FolderExists(SOURCE)) Then MsgBox "Source Folder Missing"
Now would it not make a whole lot more sense to *always* create
the source folder in case it is missing, not just after deleting it
yourself?
- The Function moveFiles(copysource, ctarget)
is a perfect example of how to confuse people and make maintenance
difficult. Why? Because, despite of its name, it does not *move* files -
it *copies*them!
- To address your main point, you need to tell us more about how the
source files get generated, e.g.
* how many are there?
* do they always have the same names?
* how often do they arrive?
* is it possible to arrange for some handshake so that new files
do not arrive while the old files get copied and old files do not
get copied while new files arrive?
Below is your cleaned-up code, minus the functionality raised in
the last point above. To make it really robust you would need to
introduce some error checking code.
Set objFSO = CreateObject("Scripting.FileSystemObject")
SOURCE = "C:\jtest"
TARGET1 = "c:\jtest1"
TARGET2 = "c:\jtest2"
TARGET3 = "c:\jtest3"
Do
'Verify if source folder exists
If Not objFSO.FolderExists(SOURCE) Then objFSO.CreateFolder SOURCE
'Run the moveFiles function
CopyFiles SOURCE, TARGET1
CopyFiles SOURCE, TARGET2
CopyFiles SOURCE, TARGET3
'Delete the TARGET folder (and contents)
objFSO.DeleteFolder SOURCE, True
'Recreate TARGET folder
objFSO.CreateFolder SOURCE
'Wait time before checking SOURCE again
WScript.Sleep 5000
Loop
Function CopyFiles(copysource, ctarget)
'Create target directory if does not exist
If Not (objFSO.FolderExists(ctarget)) Then objFSO.CreateFolder(ctarget)
'Copy files from SOURCE to TARGET
objFSO.CopyFolder copysource, ctarget
End Function 'replicateFolders
|