How do you put a variable in the middle of a pathway? (AppleScript) I am trying to write code that deletes files from a specified location and empties into the trash. If I use the direct string it works but when I try to add a variable it does not. Could someone help show me what I'm doing wrong?
When I tried to look up the error code number at the bottom, it didn't give me much insight.
Valid
tell application &quot;Finder&quot;
        delete (every item of folder &quot;Macintosh HD:Users:sme0219:Pictures:Camera&quot; whose name contains &quot;.png&quot;)
end tell

Invalid
tell application &quot;System Events&quot;
    set userName to name of current user
    set compName to name of startup disk
end tell

tell application &quot;Finder&quot;
    delete (every item of folder compName &amp; &quot;:Users:&quot; &amp; userName &amp; &quot;:Pictures:Camera&quot; whose name contains &quot;.png&quot;)
end tell

Error Report

error &quot;Can’t get {folder &quot;Applications&quot; of startup disk of application &quot;Finder&quot;, folder &quot;Library&quot; of startup disk of application &quot;Finder&quot;, folder &quot;System&quot; of startup disk of application &quot;Finder&quot;, folder &quot;Users&quot; of startup disk of application &quot;Finder&quot;, &quot;:Users:&quot;, &quot;sme0219&quot;, &quot;:Pictures:Camera&quot;} whose name contains &quot;.png&quot;.&quot; number -1728
You need to put parentheses around:
compName &amp; &quot;:Users:&quot; &amp; userName &amp; &quot;:Pictures:Camera&quot;

Example:
(compName &amp; &quot;:Users:&quot; &amp; userName &amp; &quot;:Pictures:Camera&quot;)

This concatenates everything within the parentheses as the full path, otherwise Finder just sees:
delete (every item of folder compName &amp; &quot;:Users:&quot; &amp; userName &amp; &quot;:Pictures:Camera&quot; whose name contains &quot;.png&quot;)

As:
get every item of folder &quot;Macintosh HD&quot;

Not the entire path.
So, this works:
tell application &quot;System Events&quot;
    set userName to name of current user
    set compName to name of startup disk
end tell

tell application &quot;Finder&quot;
    delete (files of folder (compName &amp; &quot;:Users:&quot; &amp; userName &amp; &quot;:Pictures:Camera&quot;) whose name contains &quot;.png&quot;)
end tell



Instead of relying on System Events to get that information, you can use the path to (folder) convention to ascertain its path, e.g.:
set targetFolder to (path to pictures folder from user domain) &amp; &quot;Camera&quot; as string

tell application &quot;Finder&quot;
    delete (files of folder targetFolder whose name contains &quot;.png&quot;)
end tell

Please take a moment to read the linked document as I believe you'll find it quite informative.
Also note that since you stated code that deletes files in the OP and your code had the potential to delete a folder having a .png extension that every item  has bee changes to files with the exception of the line after &quot;otherwise Finder just sees:&quot; in this answer as that line is part of explaining what the issue is that you are having.