• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Check for File/Folder Copy

Hi,

  What is the best way to check to make sure that one directory was copied correctly to another directory?  I have both files and folders I am copying, but I need to run a test at the end to make sure all the right files/folders are there.

Thanks for any help!

-TK

0
tkeeler1
Asked:
tkeeler1
  • 5
  • 5
1 Solution
 
[ fanpages ]IT Services ConsultantCommented:
In your Command Prompt window, type the line below followed by [RETURN]/[ENTER]:

VERIFY ON


Why would you presume the copy would fail, btw?

Do you have sufficient error handling around your FileCopy statement?

BFN,

fp.
0
 
tkeeler1Author Commented:
Hi,

  I can't use command prompt calls in my application, so I'm doing all my file/folder copies through FileSystemObject.  (See code at http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21877143.html.)  The problem is that as long as the start and destination paths exist, no errors are thrown, even if the file/folder transfer was unsuccessful.  Thus, I need to find another way to check this.

Any ideas?

Thanks,
TK
0
 
[ fanpages ]IT Services ConsultantCommented:
"even if the file/folder transfer was unsuccessful."

Why is the copy not completing?

Are any of the files in the source folder locked?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tkeeler1Author Commented:
Well, I'm trying to dummy-proof the process for end-users.  They get to pick the destination path of the files, which need to be copied to their computer.  If they accidentally pick D:\ (like the CD/DVD drive), my code sees that drive and no errors are thrown during the file copy phase!  Actually-- it's a little weird-- the first time I tried this, I got an error, but then subsequent times, there wasn't an error.  Not sure what was going on.  So now I'm trying to look at other ways of checking the file transfer....
0
 
[ fanpages ]IT Services ConsultantCommented:
So, the process doesn't fail as such, it's a user error if they select the incorrect destnation folder/drive?

Is the DVD drive a CD-RW drive?  That may explain why it fails then subsequently does not.

Either way, do you need to restrict what kind of drives, or specific folders can be selected?

How are you offering the selection process?  What code are you using?

...

This aside, you could query the contents of the destination folder before the copy starts and store this, then copy, and query again, then compare the two sets of contents.

Not ideal, though, as there's no guarantee that whilst the copy is underway, another process (or user) hasn't deleted a file (from either the source or the destination) thus resulting in a mismatched list of files on either side of the transfer.

You could make a copy of the source files to a known folder (create one on the c: drive, or the user's "temp" folder), then move these files to the selected folder.  If the temporary folder is empty after the copy then the files must now be present in the selected folder.


BFN,

fp.

0
 
tkeeler1Author Commented:
Correct: it is a user error if they select the wrong drive, but I still have to catch it.

The DVD drive is a CD-RW drive, so maybe that is why I saw the error (and then lack thereof).

Here's my full process: the user is supposed to copy a group of files and folders to a removable drive (either PCMCIA or USB).  Both show up as DRIVE_REMOVABLE (or "2") using GetDriveType (with declaration Private Declare Function GetDriveType Lib "kernel32" Alias _
       "GetDriveTypeA" (ByVal nDrive As String) As Long).

My code does the following: searches for the DRIVE_REMOVABLE, asks the user to ensure that the drive is correct, and allows them to change the drive if it isn't correct (since they may have more than one DRIVE_REMOVABLE on their computer), deletes all the files on that drive, and then copies all the folders and files there.

I guess one thing that would help would be to limit the possible destinations to only removable drives (instead of letting the user pick anything).

Also, since I am deleting everything on the drive prior to copying the files, I should be able to query the destination folder to see if it matches my start folder.  Would that be the best method do you think?

Thanks,
TK
0
 
tkeeler1Author Commented:
Code that helps me do this (query destination folders/files to see if they match source folders/files), without involving hidden dirListBoxes or fileListBoxes, which is my current solution, will be worth an extra 200 pts!  :)

TK
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi again,

Your could either redirect an MS-DOS (Command Prompt) DIR listing of the source folder to a flat ASCII file before the copy, then output the destination folder (drive) afterwards & compare the two files byte-by-byte.

Or, you could use API routines (FindFirstFile), or the FileSystemObject, or even the VB Dir() statement, to query the files in both the source & destination, storing each set in either a collection or an array, then looping through each comparing each element of the collection (or array) between both sets... as soon as element 'N' from one set does not match element 'N' from the other then the copy has failed [or indeed, if the total number of items in each set is different, then you can tell that the copy failed without comparisons].

...Or, after the copy has completed, you could loop through every file in the source folder & check to see if the same filename exists in the destination folder.

...Or, the FileSystemObject has a CopyFolder method that, as the name implies, allows you to copy one folder to another (on differing drives if you wish).  The process will either be wholly successful (i.e. all files copied), or wholly a failure (i.e. no files will be copied).  You can verify this to see if any files exist in the destination folder afterwards.  If any file is present, then the copy was OK, otherwise it was not.   Hmmm... not sure if a lack of disk space in the destination folder would cause a problem here; would have to check this via code.  But that leads to an interesting question about whether you are actually checking to see if the selected destination folder does have sufficient capacity in advance.

PS. Maybe theses PAQs will help you?

"Counting Files in a Directory..."
[ http://www.experts-exchange.com/Programming/Q_21098641.html ]

"Comparing contents two folders"
[ http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20568236.html ]


BFN,

fp.
0
 
tkeeler1Author Commented:
Okay, I did my own code using API routines.  Unfortunately, I couldn't use "CopyFolder" because I needed things in one folder stored to the root of the removable drive (CopyFolder only goes folder to folder), so it was a little messier... but I think I solved the problem of checking the files copied.  Thanks a bunch for the help, FP!

-TK
0
 
[ fanpages ]IT Services ConsultantCommented:
You're very welcome.

Thanks for closing the question.

BFN,

fp.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now