Ok, what i’m trying to do is that I have a list with all the files in a folder, then I add a file to the folder and do another list folder and compare the result to get the file that has been added.
I thought that list folder only returned the filename but I suspect that’s not the case. See the code below.
First of all i just tried to do as below to compare files in the list. This didn’t work at all, and that’s the first thing that got me to suspect list folder doesn’t return the filename.
if {an_item} is not in folder_items then
So i changed it to compare as strings. And that works.
property mac_path : ((path to desktop from user domain) as string) & "Test:"
set folder_items to list folder alias mac_path without invisibles
display dialog "Add a file to the folder"
set folder_items_2 to list folder alias mac_path without invisibles
repeat with an_item in folder_items_2
if {an_item as string} is not in (folder_items as string) then
display dialog an_item & " has been added to the folder"
set folder_items to folder_items & {an_item}
end if
end repeat
So this checks if the there is a new file added in the folder and then it adds it to the list with files. But if you now do this procedure twice in a row it doesn’t work. See the code below:
property mac_path : ((path to desktop from user domain) as string) & "Test:"
set folder_items to list folder alias mac_path without invisibles
display dialog "Add a file to the folder"
set folder_items_2 to list folder alias mac_path without invisibles
repeat with an_item in folder_items_2
if {an_item as string} is not in (folder_items as string) then
display dialog an_item & " has been added to the folder"
set folder_items to folder_items & {an_item}
end if
end repeat
display dialog "Add another file to the folder"
set folder_items_2 to list folder alias mac_path without invisibles
repeat with an_item in folder_items_2
if {an_item as string} is not in (folder_items as string) then
display dialog an_item & " has been added to the folder"
set folder_items to folder_items & {an_item}
end if
end repeat
Isn’t list folder just returning a filename. Then i should be able to manually add and manipulate these lists and just be able to do a compare without the “as string” in there.