Quantcast

Maximum PC

It is currently Thu Oct 02, 2014 1:26 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 17 posts ] 
Author Message
 Post subject: Looking for a program to copy 3 files continuously
PostPosted: Fri Jan 30, 2009 6:42 pm 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
I need a program that can copy 3 small files (x, x1, x2 - all less than 2kb) once every second, possibly more often, from directory x to directory y on the same machine. No networking support required.

Anyone know of one? Preferably free? xstarter expired on me and didnt work so well. Any ideas?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 8:37 pm 
Clawhammer
Clawhammer
User avatar

Joined: Sat Jun 26, 2004 2:16 pm
Posts: 3600
Are you just testing a connection or what?


Top
  Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2009 12:01 am 
Team Member Top 50
Team Member Top 50

Joined: Sat Jun 25, 2005 11:04 am
Posts: 1026
Might be able to have a script running in the background doing the copying.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2009 7:17 am 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
I was thinking a script could handle it too, but I don't know much about scripting environments in windows.

alex the less info I post the easier it will be to find a solution.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2009 9:29 am 
Clawhammer
Clawhammer
User avatar

Joined: Fri Sep 23, 2005 6:22 pm
Posts: 4406
Location: In the closet
You want Karen's Replicator


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 10:19 am 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
No I don't, the fastest it can apply a job is once every minute. Same with most other backup applications like cobian etc. I specifically stated every second or faster.

Honestly whats so hard about reading a few sentences? I even used spell check, punctuation and capitalization.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 10:45 am 
Clawhammer
Clawhammer
User avatar

Joined: Fri Sep 23, 2005 6:22 pm
Posts: 4406
Location: In the closet
First off, FU!

Second off, change the frequency to seconds with her posted hack!


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 12:20 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Save as a .vbs. Run as you wish, create a scheduled task in Windows, whatever.

Code:
Option Explicit

Dim objFSO, objFileCopy1, objFileCopy2, objFileCopy3
Dim strFilePath1, strFilePath2, strFilePath3
Dim strTargetFilePath1, strTargetFilePath2, strTargetFilePath3

strFilePath1 = "c:\file1.txt"
strFilePath2 = "c:\file1.txt"
strFilePath3 = "c:\file1.txt"

strTargetFilePath1 = "d:\file1.txt"
strTargetFilePath2 = "d:\file1.txt"
strTargetFilePath3 = "d:\file1.txt"

' Copy the file to its destination, do this 3 times
For count = 0 to 3
   'Set up objects
   Set objFileCopy1 = objFSO.GetFile(strFilePath1)
   Set objFileCopy2 = objFSO.GetFile(strFilePath2)
   Set objFileCopy3 = objFSO.GetFile(strFilePath3)
   
   'Do the copy
   objFileCopy1.Copy (strTargetFilePath1)
   objFileCopy2.Copy (strTargetFilePath2)
   objFileCopy3.Copy (strTargetFilePath3)
   
   'Sleep for 3 seconds
   WScript.sleep 3
Next

Wscript.Quit


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 3:12 pm 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
kleinkinstein wrote:
First off, FU!

Second off, change the frequency to seconds with her posted hack!

There's a hack? You have to hack the program to get seconds? I didn't see any mention of that on the page, or in your post.

Crashtech thank you, can I use decimals in place of the seconds value? (IE 1.1, .5, etc)


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 4:03 pm 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
Nuts I'm getting an error with the script crash. First it said count was undefined so I added "dim count" to the top hoping that was the proper syntax to create the variable.

Now the problem is as follows:
"Script: C:\pathhere\script.vbs
Line 19
Char 4
Error: Object required: "
Code: 800A01A8
Source: Microsoft VBScript runtime error"

Any ideas? I'm guessing something in the set up objects section is improperly formatted.

Thanks again.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 4:08 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Try this. I added the count var like you mentioned in your PM.

Code:
Option Explicit
Dim count
Dim objFSO, objFileCopy1, objFileCopy2, objFileCopy3
Dim strFilePath1, strFilePath2, strFilePath3
Dim strTargetFilePath1, strTargetFilePath2, strTargetFilePath3

'''''''''' ADDED ''''''''''
Set objFSO = CreateObject("Scripting.FileSystemObject")

strFilePath1 = "c:\file1.txt"
strFilePath2 = "c:\file1.txt"
strFilePath3 = "c:\file1.txt"

strTargetFilePath1 = "d:\file1.txt"
strTargetFilePath2 = "d:\file1.txt"
strTargetFilePath3 = "d:\file1.txt"

' Copy the file to its destination, do this 3 times
For count = 0 to 3
   'Set up objects
   Set objFileCopy1 = objFSO.GetFile(strFilePath1)
   Set objFileCopy2 = objFSO.GetFile(strFilePath2)
   Set objFileCopy3 = objFSO.GetFile(strFilePath3)
   
   'Do the copy
   objFileCopy1.Copy (strTargetFilePath1)
   objFileCopy2.Copy (strTargetFilePath2)
   objFileCopy3.Copy (strTargetFilePath3)
   
   'Sleep for 3 seconds
   WScript.sleep 3
Next

Wscript.Quit


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 4:52 pm 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
It's working now thanks. Just a few more questions:

1) Can I use values with decimals instead of whole seconds?
2) Whats the formatting for a never ending loop in VBS? At the moment it will just copy the files 3 times it looks like. I need it to run for 5 to 50 minutes. I mean I guess I could just do that math and set it from 0 to (X minutes times 60 with a 1 second sleep) but I was hoping for a different method.

Or maybe something that pops up a warning that the script isnt running anymore?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 6:26 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
I think the sleep function actually takes milliseconds. So that is my bad.

http://mikesalsbury.com/2005/06/vbscrip ... ction.html

I really don't know that a never-ending loop is a really good idea. I guess you could try to have it run till you hit a key combination?

I haven't written VBS in quite a while, so I am not sure how to go about it. You probably could use a timer and edit the file before you run it to change how long it runs for?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 7:42 pm 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
at the moment I just wrote a basic loop to ask if it should run again like so:

Code:
i=0
do while i < 1

' Copy the file to its destination, do this 3 times
For count = 0 to 900
   'Set up objects
   Set objFileCopy1 = objFSO.GetFile(strFilePath1)
   Set objFileCopy2 = objFSO.GetFile(strFilePath2)
   Set objFileCopy3 = objFSO.GetFile(strFilePath3)
   
   'Do the copy
   objFileCopy1.Copy (strTargetFilePath1)
   objFileCopy2.Copy (strTargetFilePath2)
   objFileCopy3.Copy (strTargetFilePath3)
   
   'Sleep for 1 second
   WScript.sleep 1
Next

'Checks if you want to run the loop again
dim answer
answer=MsgBox("Finished, run again?!",4,"Loop")

if answer = 6 then
i=0
else
i = 1
end if

loop


Lol I figured it wasn't seconds, considering it took less than 5 seconds to complete when i set count to go to 900. I should have remembered vb likes milliseconds from my VB days >_<


Top
  Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 5:18 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
I didn't even realize it. I yanked some sample code and dropped it in there.

I am sure you could set something basic that will ask the target time to run and do some math for you?


Top
  Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 3:04 pm 
Smithfield
Smithfield
User avatar

Joined: Sun Sep 05, 2004 9:01 am
Posts: 8091
You underestimate my laziness when it comes to programming. I gave up on CS along time ago as not worth it. Scripting is kinda more useless to me because there are so many versions of so many types of scripting. I can usually work out the gist of a script in my head anyways.

I found a value that gives me 16~ minutes of run time and that should do me just fine. Thankfully it doesn't tell the file system to create x(1).txt, x(2).txt ad infinitum.... or I'd have one hell of a full dir right now :P

Ty for all the help.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 3:57 pm 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Mon Jan 08, 2007 1:41 pm
Posts: 2033
now let me show you the easy way.. =)

simplest method is to use a batch file. Three lines of code basically to copy three files. Only problem is that there isn't any batch file command in xp or vista to "sleep" or "delay" or whatever. That can be remedied with a few more lines of c++.

Batch file: copy_file.bat
Code:
@ECHO OFF
copy C:\files\file1.txt C:\newlocation\file1.txt
copy C:\files\file2.txt C:\newlocation\file2.txt
copy C:\files\file3.txt C:\newlocation\file3.txt
EXIT


C++ to automate the sleep - run.cpp
Code:
#include <stdlib.h>
#include <windows.h>
int main() {
  while(1)
  {
  system("copy_file.bat");
  Sleep(1000);
  }
}

Download the .exe for the c++ code here.

Name the batch file "copy_file.bat" and save it in the same folder as run.exe. When you double click the executable it will start copying the files every one second. Obviously any extras would be easy to add to the c++ code... not sure exactly what you'd want though. It's even possible to have the c++ program ask which files you want and automatically generate the accompanying batch file.

I can make the delay between copies shorter than one second, but I imagine too short and we'd start impacting disk performance?


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.