×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

waiting for copyhere command to complete
2

waiting for copyhere command to complete

waiting for copyhere command to complete

(OP)
Hi,

I'm using the copyhere command to transfer a large amount of files into a zipfile before moving the zip file to a different location on the network (and it has to happen in this order).

I want to wait with moving the file across the network until the copying is done. The only thing I could think of was a Do While loop with a sleep command in it but this is really messing up my system performance though it does seem to work. Can you think of a better way of waiting for the copyhere to complete?

I've included the code I'm using below. All the way at the bottom are two loops. The second loop is the one that waits for the copyhere command to complete. The loop before it is the copyhere command which reads a textfile to find the folders it needs to include.

Your help would be very much appreciated.

Const FOF_SIMPLEPROGRESS = &H100

Set objShell = CreateObject("Shell.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set DestFldr=objShell.NameSpace("C:\test1\"&UserName&" "&Date()&".zip")

Set fso = nothing
Set ts = nothing

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\test1\test.txt",ForReading)
i = 0

Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    DestFldr.CopyHere (strNextLine)", FOF_SIMPLEPROGRESS = &H100
    i = i + 1
Loop

Do While objShell.NameSpace("C:\test1\"&UserName&" "&Date()&".zip").items.Count < i
wscript.sleep 5000
Loop

RE: waiting for copyhere command to complete

You may try this:
DestFldr.CopyHere strNextLine, 16

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886

RE: waiting for copyhere command to complete

(OP)
Thank you PHV but that doesn't seem to help. I think I need to find a different way of checking whether the copying process is complete.

RE: waiting for copyhere command to complete

2
[1] >I'm using the copyhere command to transfer a large amount of files into a zipfile

[1.1] If that is "large amount of files", then you better not user copyhere approach. It is ultra slow. Why don't you use fso to do that?

[1.2] According to the script you have shown.
>Set DestFldr=objShell.NameSpace("C:\test1\"&UserName&" "&Date()&".zip")
The xxx.zip is a folder name, I suppose. How would the files be copied "into" a zipfile???

[2] >I want to wait with moving the file across the network until the copying is done. The only thing I could think of was a Do While loop with a sleep command in it but this is really messing up my system performance though it does seem to work.

I don't think your loop with sleep is doing anything good as copyhere should perform synchronous copy. It blocks the script progression to the next line. And, I know it can do something bad. What if some file name read from the text file is missing from the source folder. In that case, the loop will be looping forever. (Maybe that's what you are observing in some case... and remember [1], even though every file is found, the copyhere is ultra slow and can take a long time.)

[3]>DestFldr.CopyHere (strNextLine)", FOF_SIMPLEPROGRESS = &H100

Those highlighted cannot be right. Furthermore, you should not only add 16 as PHV suggested, you should at least add 1024 to suppress interface when error occurs. Hence, the vOptions should be minimally this.

    DestFldr.CopyHere strNextLine,16+256+1024

Enough sofar for you to revise the script.

RE: waiting for copyhere command to complete

(OP)
Tsui, thank you for your very clear reply. I will try to use the FSO command and add the extra parameters. By the way the " sign was a copy-paste problem into this forum but thank you for noticing.

By the way you can use the copyhere command to copy files into zip folders.

RE: waiting for copyhere command to complete

Thanks for the feedback and the vote.

>By the way you can use the copyhere command to copy files into zip folders
Yes, zip "folder" not a zip "file", I hope. Otherwise the number of file at the destined folder remained 1 (or unchanged) and the final loop will either definitely indefinite or of doubtful meaning. (Maybe I really miss something.)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close