Scan a folder for file

I want to scan a folder for files and if there are not there to give a notification if the are there then to proceed with a Macro. I've been told by Peter a "For Each Action" rule. Attached is what he proposed. The issue is that I want to scan the folder for three files and if they are there then activate a Macro. If not then to provide a notification that they are not there. Thanks for looking into this form me Regards
Brian

Hey Brian,

There's more than one way to do this task, but the simplest method is probably thus:

If Files Exist… Then….kmmacros (6.7 KB)

I personally would likely use AppleScript, but it depends upon the rest of the task.

set file1 to ((path to downloads folder as text) & "KM_URL-File_Test 01.txt")
set file2 to ((path to downloads folder as text) & "KM_URL-File_Test 02.txt")
set file3 to ((path to downloads folder as text) & "KM_URL-File_Test 03.txt")

set fileList to {file1, file2, file3}

set AppleScript's text item delimiters to ":"

repeat with i in fileList
  try
    alias i
    display notification "File " & (last text item of (i as text)) & " Exists." with title "Keyboard Maestro Notification"
    # Add code to post-process file if necessary.
  on error
    display notification "File " & (last text item of (i as text)) & " is missing!." with title "Keyboard Maestro Notification" sound name "Sosumi"
    # Add code to download file.
  end try
  delay 1
end repeat

--
Best Regards,
Chris

Okay, let’s simplify that AppleScript a bit:

set sourceFolder to path to downloads folder as text

set fileNameList to {¬
  "KM-File_Test_01.txt", ¬
  "KM-File_Test_02.txt", ¬
  "KM-File_Test_03.txt"}

set AppleScript's text item delimiters to ":"

repeat with i in fileNameList
  try
    alias (sourceFolder & i) # Errors if file does NOT exist.
    display notification "File " & (last text item of (i as text)) & " Exists." with title "Keyboard Maestro Notification"
    # Add code to post-process file if necessary.
  on error
    display notification "File " & (last text item of (i as text)) & " is missing!." with title "Keyboard Maestro Notification" sound name "Sosumi"
    # Add code to download file.
  end try
  delay 1
end repeat

-ccs

Thanks for getting back to me. Will try it later. Basically if those files exist then they will activate a Macro. But it has to be three files not one not two. So this will work doing it this method…
Regards
Brian

If you just want to know if there specific files exist at specific paths, you can just use an If Then Else action with three path conditions.

Thanks for the reply. I tried your previous solution and it worked. Very impressed with this software.
Regards
Brian