Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Script for news items

Reply
Thread Tools Display Modes

Re: Script for news items

 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      03-16-2010


"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


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      03-17-2010


"Jonathan Duane" <> wrote in message
news:188c5394-1535-459c-866c-...
>
> Hi,
>
> I really appreciate the prompt reply..Ok this is what happens, i work
> for a radio station and we have stations across the country, we have a
> news server were people record their audio clips and create txt
> filesto read, when they are created on the news server, the news
> serverthen (through a process called internal newswires copys them to
> a unc path e.g \\servername\share they come in at random times and
> random sizes (depends how big the audio clip is really) but the text
> files will always be around the same size it is when they are copied
> to the \\servername\share from the news server i want the scipt to run
> and then copy the audio clips and text files into different locations
> around the country that are connected through UNC paths via VPN
>
> Again thank you so much for your help


I can think of two methods to avoid the occasional conflict:
a) You can arrange for some dialog between the NewsWires process
and your own copy process.
b) You rely on a minimum time gap between two successive
transmissions from the NewsWires process (e.g. 5 minutes)

 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IMAP Deleted and Sent items - some answers decomplexity Windows Live Mail 7 06-15-2010 11:06 PM
logon script for mapping Bonno Bloksma Scripting 1 11-27-2009 05:18 PM
Is Windows Vista index-based full-text search powerful enough? Peter Frank Windows Vista File Management 47 03-23-2007 05:54 PM
Some contacts not syncing TC ActiveSync 12 07-10-2006 03:47 AM
Keep just recent items on PPC, but keep all calendar items on PC? Fr@nk ActiveSync 3 06-10-2006 04:25 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59