Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

waiting for copyhere command to complete 2

Status
Not open for further replies.

chriskuyper

Technical User
May 18, 2006
5
NL
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
 
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
 
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.
 
[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.
>[tt]Set DestFldr=objShell.NameSpace("C:\test1\"&UserName&" "&Date()&".zip")[/tt]
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]>[tt]DestFldr.CopyHere (strNextLine)[highlight]"[/highlight], FOF_SIMPLEPROGRESS [highlight]= &H100 [/highlight][/tt]

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.

[tt]DestFldr.CopyHere strNextLine,16+256+1024[/tt]

Enough sofar for you to revise the script.
 
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.
 
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.)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top