Verifying copied files with the originals

Thanks regulus6633 for the tip. http://macscripter.net/viewtopic.php?id=33933

My script keeps progressing. After running the script I came to mind that I would have to be more cautious before emptying the card. Especially since, at the beginning, the files are only stored on the card.

I’ve decided when duplicating the card information I would do it onto two different hard drives. The first one being the computer hard drive and then en external FW800 drive.

However, I still have the problem to ensure all files located on SDHC card have been copied over.

The workflow will then be the following:
1 - Copy all files stored on the SDHC card onto the computer hard drive;
2 - Verify if all the files copied onto the computer hard drive are equal to the one stored on the SDHC card;
3 - Copy verified files from the computer hard drive to the external hard drive;
4 - Verify again the files copied over form the computer hard drive are equal to the one located on the external hard drive;
5 - Move all files located on the external hard drive to their correct location i.e using the name NIK001* NIK002* create a subfolder 01 for all files starting with NIK001*, create a subfolder 02 for all files starting with NIK002*
6 - Delete all files located on the SDHC card;
7 - Eject the card and notify the operator.

At this moment my script is performing correctly steps #1, #3, #6 and #7.

Step #5 I have sufficient information, the tip provided by regulus6633 pointed me on the right direction, I should be able to efficiently write this function.

Step #2 and #4, I am currently programming and having difficulties.

I wish comparing the variables theCardFile with theDumpFile would have been sufficient. This does not seem to be the case. I believe what is happening is that those variables not only contains the filenames but also the path describing were they were coming from.

  • If this is the case is there a quick function which would allow me to remove path and rebuilt the array for comparisons.

I am trying to see the content of those two variables in doing a display dialog. This does not work I get an error message.

  • Would someone know how to display the content of those variable onto the screen?
  • Am i on the right track by comparing the variable theCardFile to theDumpFiles?

Thanks again!
Daniel

set destinationFolder to (path to home folder as text) & "NIKON:dumpNIKON:"
display dialog destinationFolder

tell application "Finder"
	
	set inputFolder to folder "DCIM:" of disk "NIKON" as string
	set theCardFiles to files of folder inputFolder whose name begins with "NIK001"
	set theDumpFiles to files of folder destinationFolder whose name begins with "NIK001"
	duplicate theCardFiles to folder destinationFolder with replacing
	if theDumpFiles is equal to the theCardFiles then
		display dialog "Files copied on the hard drive are identical to the one stored on the SDHC card. You can now remove all files starting with NIK001 located on the SDHC card"
	else
		display dialog "Files copied on the hard drive are not identical to the one stored on the SDHC card. NOthing will be removed from the SDHC card"
	end if
	
end tell

Here’s how to be certain that the copy is the same as the original. You check their checksum. For example as a test, copy a file from and external drive to your internal hard drive. Then run this script choosing both files. It will tell you if their checksums match. If they match then the copy was successful… if not the copy was unsuccessful. So you can use this technique to validate your copy operations.

-- SHA-1 checksum verifier
-- md5 is considered outdated so we use this one instead
-- this will calculate the sha1 checksum of 2 files, compare them, and let you know if they're the same

set file1 to choose file without invisibles
tell application "Finder" to set f1 to name of file1

set file2 to choose file without invisibles
tell application "Finder" to set f2 to name of file2

try
	set r1 to do shell script "openssl dgst -sha1 -c  " & quoted form of (POSIX path of file1)
	set r2 to do shell script "openssl dgst -sha1 -c  " & quoted form of (POSIX path of file2)
	set text item delimiters to ")= "
	set sha1_f1 to item 2 of (text items of r1)
	set sha1_f2 to item 2 of (text items of r2)
	set text item delimiters to ""
	
	if sha1_f1 is equal to sha1_f2 then
		set match_text to "The sha1 checksums match"
	else
		set match_text to "The sha1 checksums do not match"
	end if
	
	tell me
		activate
		display dialog match_text & return & return & f1 & return & sha1_f1 & return & return & f2 & return & sha1_f2 buttons {"OK"} default button 1 with icon note
	end tell
on error theError number errorNumber
	tell me
		activate
		display dialog "There was an error:" & return & theError & return & return & "Error Number: " & errorNumber as text buttons {"OK"} default button 1 with icon stop
		return
	end tell
end try

Thank regulus6633,

The script works in the situation I need to verify one file at a time.

What about many files, I could be copying 50 files from a specific folder “101PNv01” on the SDHC card to the another folder on the computer hard drive (step #1 and #3)).

I need to ensure all files copied from one folder to another are the same (step #2 and #4).

In my verification I need to ensure that I’ve copied the exact same number of file and I need to make sure those are the same file.

All of those steps are to be executed automatically from a script, no user selection.

Is there a way this can be done in a bulk?

I’ve tried something with this function.

Each dialog box is showing the name (i) of mpeg files one by one. Is there a way I could concatenate only the names without their folder path.

To concatenate I would use a repeat loop for the number of mpg files registered in listOfFiles.

I would execute this function on the SDHC card, the folder of the computer hard drive and the external drive.

This would not be the best but it would sure give me something to compare. The problem I have at the moment is the path folder of each files is carried over. I only want to concatenate onto one variable the name of each files being copied.

Is there a way for me to do this?

Thanks!
Daniel

tell application "Finder"
	
	set listOfFiles to (sort (every file in folder "NIKON:MP_ROOT:101PNV01:" whose name extension is "MPG") by name)
	set countOfListOfFiles to count of listOfFiles
	
	set fileInitiator to item (1) of listOfFiles
	set fileInitiatorName to name of fileInitiator
	display dialog fileInitiatorName
	
	set fileInitiator to item (2) of listOfFiles
	set fileInitiatorName to name of fileInitiator
	display dialog fileInitiatorName
	
	set fileInitiator to item (3) of listOfFiles
	set fileInitiatorName to name of fileInitiator
	display dialog fileInitiatorName
	
	display dialog listOfFiles
	if listOfFiles = {} then
		display dialog "There is no MPEG files on the card"
		error number -128
	end if
end tell

Regards!
Daniel

I’m sure you can figure that out. You just need a list of the original files and a list of the copied files. Then repeat through the list and compare the sha1 digest one at a time. If something doesn’t match then alert yourself.