Determine if a record is in a list of records

I’m a newbie, and I’m trying to determine if a record is in a list of records:

I fist create a list of records with this portion of script:


set bSF to bSF as alias
set aFiles to every file of bSF
repeat with aFile in aFiles
	set aMod to modification date of aFile
	set aUrl to aFile as alias
	set row to {aUrl:aUrl, aMod:aMod}
	copy row to the end of oldFiles
end repeat

Then I try to know if a record is in the list with these:


repeat with newFile in newFiles
	set aMod to modification date of newFile
	set aUrl to newFile
	set row to {aUrl:aUrl, aMod:aMod}
	if row is in oldFiles then
		copy row to the end of tempFiles
		set backup to true
	end if
end repeat

But this fails.
I don’t know if there is another way to do this, or if I’m doing something wrong.

Please Help me,
Cuco

Hi Jaime,

your script ist almost o.k, but
file and modification date are terms of the Finder,
so you need a tell block to target the Finder

set bSF to bSF as alias
tell application "Finder"
	set aFiles to every file of bSF
	repeat with aFile in aFiles
		set aMod to modification date of aFile
		set aUrl to aFile as alias
		set row to {aUrl:aUrl, aMod:aMod}
		copy row to the end of oldFiles
	end repeat
end tell

or

set bSF to bSF as alias
tell application "Finder" to set aFiles to files of bSF
repeat with aFile in aFiles
	copy {aUrl:modification date of (info for of (aFile as alias)), aMod:aFile as alias} to the end of oldFiles
end repeat

First of all, thanks for the response, but the tell finder is in my entire script:

property SF : "Macintosh HD:Users:Mac:Desktop:Prueba Backups"
property BF : "Macintosh HD:Users:Mac:Desktop:Prueba Backups:Backup Zone"

set backup01 to crearBackItUp(SF, BF)
set backup02 to crearBackItUp(SF, BF)

tell backup01 to iniciar()
tell backup01 to buscaNuevos()

tell backup02 to iniciar()

on idle
	tell backup02 to buscaNuevos()
end idle

on crearBackItUp(backupSourceFolder, backupDestinyFolder)
	
	script backItup
		property bSF : backupSourceFolder
		property bBF : backupDestinyFolder
		property oldFiles : {}
		property oldNames : {}
		property backup : false
		
		on iniciar()
			tell application "Finder"
				set bSF to bSF as alias
				set aFiles to every file of bSF
				repeat with aFile in aFiles
					set aMod to modification date of aFile
					set aUrl to aFile as alias
					set row to {aUrl:aUrl, aMod:aMod}
					copy row to the end of oldFiles
				end repeat
			end tell
		end iniciar
		
		on buscaNuevos()
			tell application "Finder"
				set backup to false
				set newFiles to (every file of bSF)
				set tempFiles to {}
				set tempOldNames to {}
				repeat with i from 1 to count of oldFiles
					if ((item i of oldFiles) as record) is in newFiles then
						copy item i of oldFiles to the end of tempFiles
					end if
				end repeat
				repeat with newFile in newFiles
					set aMod to modification date of newFile
					set aUrl to newFile
					set row to {aUrl:aUrl, aMod:aMod}
					if row is not in oldFiles then
						copy row to the end of tempFiles
						set backup to true
					end if
				end repeat
				display dialog (backup)
				if backup is true then
					set oldFiles to tempFiles
					set oldNames to tempOldNames
					set backup to false
				end if
			end tell
			return backup
		end buscaNuevos
		
		on comparaMods()
			tell application "Finder"
			end tell
		end comparaMods
	end script
end crearBackItUp

Sorry, Jaime, I missunderstood your problem.
It’s not possible in AppleScript to determine values in a list of records.
I would use two separated lists instead

Ok, thanks again.

I will try to do with 2 lists, :frowning:

Hi Jaime,

You have to double up the brackets. e.g.

set db to {}
repeat with i from 1 to 3
set rec_temp to {a:i}
set end of db to rec_temp
end repeat
{{a:2} is in db, {{a:2}} is in db}

Result:
– {false, true}

Edited: for moer info, see Bill Cheeseman’s article on comparing lists of lists.

http://applescriptsourcebook.com/viewtopic.php?pid=60332#p60332

gl,

oops, thanks kel, I didn’t know that.
Even in Matt Neuburg’s The Definitive Guide there is nothing written about this possibility

You’re welcome Stefan and thanks to Bill Cheeseman. He wrote some good stuff.

So Jaime, would do this:

if {row} is in oldFiles then

and BTW, I would stay away from one word variables like ‘row’. Not a good idea.

gl,

Thanks kel, I was sure that it must be a way to do this!!!

But now I have another trouble, I do this for searching for new files in the folder, and discard the files that was deleted, but when I do my repeat, it brings a dialog that tell that the file can´t be found.

I don’t know how to solve this.

I tried what you say to me, but with this:


repeat with newFile in newFiles
	set aMod to modification date of newFile
	set aUrl to newFile
	set row to {aUrl:aUrl, aMod:aMod}
	if {row} is not in oldFiles then
		copy row to the end of tempFiles
		set backup to true
	end if
end repeat

Does not work :frowning:
Thank you very much,
Cuco

Please excuse my last post, I forgotten a “as alias” and that was what made the script fails.

Now it works fine!!!

But I have the problem with the deleted files and the dialog that says “the file HD:etc… wasn’t found”

Thanks anyway.