\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > For Each loop not working correctly?


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
Can someone please help me here? This is a code snippet of a much bigger subroutine used to copy PST files from a bunch of remote computer onto a backup server. It works by mapping a drive to the remote machine, copying the files as if they were local to a local directory where the final folder is the remote computer\'s name, disconnecting the drive, and then remapping it to another computer. It keeps copying just one file off of every computer, even if there are more files there. Even if the computer doesn\'t have the target folder and any PST files, the one file still shows up on the server as if it had been copied from the computer that didn\'t have it. I can\'t figure out what the deal is; please help.
\r\n
\r\n
\r\n
Code:
\r\n
Set folderObj = FSO.GetFolder(mapDrive & Right(remoteDir, (Len(remoteDir) - 2)))\r\n \r\nIf Dir(localDir & client(counter).computer, vbDirectory) = "" Then\r\n MkDir localDir & client(counter).computer\r\nEnd If\r\n \r\nsizeCounter = 0\r\nfileCounter = 0\r\nFor Each fileObj In folderObj.Files\r\n sizeCounter = sizeCounter + fileObj.Size\r\n fileCounter = fileCounter + 1\r\n\r\n lblStatus.Caption = "Copying: " & fileObj.name\r\n Me.Refresh\r\n\r\n FSO.CopyFile fileObj.Path, localDir & client(counter).computer & "\\", True\r\n \r\n Sleep (500)\r\n Set fileObj2 = FSO.GetFile(localDir & client(counter).computer & "\\" & fileObj.name)\r\n If fileObj2.Size <> fileObj.Size Then\r\n With current\r\n .pstQuantity = client(counter).pstQuantity\r\n .pstSize = client(counter).pstSize\r\n .status = "ERROR"\r\n .statusDesc = "File did not copy correctly. Disconnecting from client to avoid further issues."\r\n .success = False\r\n End With\r\n errorCounter = errorCounter + 1\r\n Call log.documentClient(current, counter)\r\n Exit For\r\n End If\r\n \r\n log.printNote ("Successfully copied file: " & fileObj.name & " Size: " & fileObj.Size)\r\nNext fileObj\r\n \r\nWith current\r\n .pstQuantity = fileCounter\r\n .pstSize = sizeCounter\r\n .status = "Complete"\r\n .success = True\r\n .statusDesc = "PST file backup completed successfully."\r\nEnd With\r\nCall log.documentClient(current, counter)\r\n\r\nIf Not (disconnDrive(counter)) Then\r\n log.printNote ("ERROR: An error occurred while disconnecting the")\r\n log.printNote ("mapped drive. Execution Aborted")\r\n \r\n Call unloadProcedure\r\nEnd If
\r\n
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; pd[728146] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 04-26-2004, 04:00 PM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n
Ineluki\'s Avatar\r\n\r\n
\r\n \r\n Ineluki\r\n Ineluki is offline\r\n\r\n\r\n
Prev Previous Post   Next Post Next
  #1  
Old 04-23-2004, 02:54 PM
Ineluki's Avatar
Ineluki Ineluki is offline
Centurion
 
Join Date: Apr 2004
Location: Missouri
Posts: 145
Angry For Each loop not working correctly?


Can someone please help me here? This is a code snippet of a much bigger subroutine used to copy PST files from a bunch of remote computer onto a backup server. It works by mapping a drive to the remote machine, copying the files as if they were local to a local directory where the final folder is the remote computer's name, disconnecting the drive, and then remapping it to another computer. It keeps copying just one file off of every computer, even if there are more files there. Even if the computer doesn't have the target folder and any PST files, the one file still shows up on the server as if it had been copied from the computer that didn't have it. I can't figure out what the deal is; please help.

Code:
Set folderObj = FSO.GetFolder(mapDrive & Right(remoteDir, (Len(remoteDir) - 2))) If Dir(localDir & client(counter).computer, vbDirectory) = "" Then MkDir localDir & client(counter).computer End If sizeCounter = 0 fileCounter = 0 For Each fileObj In folderObj.Files sizeCounter = sizeCounter + fileObj.Size fileCounter = fileCounter + 1 lblStatus.Caption = "Copying: " & fileObj.name Me.Refresh FSO.CopyFile fileObj.Path, localDir & client(counter).computer & "\", True Sleep (500) Set fileObj2 = FSO.GetFile(localDir & client(counter).computer & "\" & fileObj.name) If fileObj2.Size <> fileObj.Size Then With current .pstQuantity = client(counter).pstQuantity .pstSize = client(counter).pstSize .status = "ERROR" .statusDesc = "File did not copy correctly. Disconnecting from client to avoid further issues." .success = False End With errorCounter = errorCounter + 1 Call log.documentClient(current, counter) Exit For End If log.printNote ("Successfully copied file: " & fileObj.name & " Size: " & fileObj.Size) Next fileObj With current .pstQuantity = fileCounter .pstSize = sizeCounter .status = "Complete" .success = True .statusDesc = "PST file backup completed successfully." End With Call log.documentClient(current, counter) If Not (disconnDrive(counter)) Then log.printNote ("ERROR: An error occurred while disconnecting the") log.printNote ("mapped drive. Execution Aborted") Call unloadProcedure End If
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MAJOR problem after using Make file.exe - app is not working correctly! HELP! VBKid04 General 7 04-21-2004 09:08 AM
weird loop necro General 2 12-04-2003 03:36 PM
Hot Keys exiting a loop Blaggut General 12 08-08-2003 07:57 AM
questions about do while loop.... Jawbreaker4Fs General 2 01-07-2003 08:12 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->