Hi all,
I am very very new to programming and have found the forums here to be an enormous source of help for me. So thank you so much!
I have been trying to program an application for some weeks now with the help of the forums but I have run into some problems that i am struggling to resolve. I hope maybe you guys could help shed some light on it.
The essence of what I am trying to do is take in a folder, create a loop to md5 the files in it and then store the names and md5 sums into a variable. Next I will duplicate the folder and repeat the process to md5 and store the information into a second variable. Then I will compare both the variables to verify that they are the same. I will also be displaying the contents of the variable into a log file.
This is my current code. Somehow I am unable to include the file name into the variable and it also takes very long time (30-40 seconds..) to display the output and the screen freezes as well. Please take a look and tell me how I may resolve this. Thank you.
-------------------------------
global gLogData
global HashValue
on mouseUp
answer folder ("Select your folder containing the Database")
put it into fld 1
put logData(fld 1) into tLog[1] -------- logData is a function that will timestamp the content in fld 1 and store into an array
answer "Create a duplicate of selected folder"
answer folder ("Select destination to copy the Database to")
put it into fld 2
put cr & logData(fld 2) into tLog[2]
combine tLog using return
put tLog into fld 3
local tDefault, tItems
set the defaultFolder to fld 1
put empty into field 4
put the files into tItems
filter tItems without "."
repeat for each line xLine in tItems
put cr & "name=" & quote & xLine & quote into HashValue[xLine]
put cr & "checksum=" & quote & fileDigest(the defaultFolder & "/" & xLine) & quote & return into HashValue[xLine]
end repeat
combine HashValue using return
put HashValue into fld 4
end mouseUp
Creating an array through a loop
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Creating an array through a loop
HI..
I only checked your script for compliance, since I do not have the other functions you mentioned. So I simply substituted short strings for whatever would have been returned by those functions.
Nothing untoward, and the process proceeded instantaneously. Is it possible that the functions themselves are taking the extra time?
Craig Newman
I only checked your script for compliance, since I do not have the other functions you mentioned. So I simply substituted short strings for whatever would have been returned by those functions.
Nothing untoward, and the process proceeded instantaneously. Is it possible that the functions themselves are taking the extra time?
Craig Newman
Re: Creating an array through a loop
Hi Gautami,
1. welcome to the forum!
2. you are OVERWRITING the filename with the checksum in your repeat loop:
...
put cr & "name=" & quote & xLine & quote into HashValue[xLine]
## BAD:
## put cr & "checksum=" & quote & fileDigest(the defaultFolder & "/" & xLine) & quote & return INTO HashValue[xLine]
## HashValue[xLine] already has a value in it - the filename, but this line will overwrite this
## Good:
put cr & "checksum=" & quote & fileDigest(the defaultFolder & "/" & xLine) & quote & return AFTER HashValue[xLine]
...
Depending on the size of your files, md5digest will take some time, I think.
Best
Klaus
1. welcome to the forum!

2. you are OVERWRITING the filename with the checksum in your repeat loop:
...
put cr & "name=" & quote & xLine & quote into HashValue[xLine]
## BAD:
## put cr & "checksum=" & quote & fileDigest(the defaultFolder & "/" & xLine) & quote & return INTO HashValue[xLine]
## HashValue[xLine] already has a value in it - the filename, but this line will overwrite this
## Good:
put cr & "checksum=" & quote & fileDigest(the defaultFolder & "/" & xLine) & quote & return AFTER HashValue[xLine]
...
Depending on the size of your files, md5digest will take some time, I think.
Best
Klaus
Re: Creating an array through a loop
Hi Klaus and Dunbarx,
Oh I see! I was worried because the function returned 1/2 the input before freezing for a while,
but now I realise the error. I will have to do something abt the function, at least put up a warning in future, I suppose.
Thank you!
Gautami
Oh I see! I was worried because the function returned 1/2 the input before freezing for a while,
but now I realise the error. I will have to do something abt the function, at least put up a warning in future, I suppose.
Thank you!
Gautami