0
votes

I am trying to dupe the file from one folder to another folder with below codes.

on run {input, parameters}

set collectPaths to {}
repeat with i from 1 to (input count)
    set collectPaths to item i of input as string
end repeat

tell application "System Events"
    set fileList to (every folder of folder collectPaths whose name is "Old")
    if (count of fileList) is equal to 0 then
        tell application "Finder"
            set x to make new folder at input with properties {name:"Old"}
        end tell
    else
        set x to fileList
    end if
end tell

tell application "System Events"
    set fileList to (every file of folder collectPaths whose name extension is "ai")
    repeat with i from 1 to count of fileList
        set theItem to item i of fileList
        tell application "Finder"
            duplicate the file theItem to the folder x
        end tell
    end repeat
end tell

end run

But I got an error as "The action “Run AppleScript” encountered an error: “Finder got an error: Can’t make alias of folder "Old" of folder "untitled folder 2" of folder "Desktop" of folder "asuvathdhamank" of folder "Users" of startup disk into type string.”

Please help me out from this and dupe the file on that Old folder

1

1 Answers

0
votes

First of all, your first loop is pointless. At the exit, CollectPath will contain the last item of input and do nothing else. To run input elements, simply use this :

repeat with collectPaths in inputs
   display dialog "Hello, " & collectPaths
   -- put your whole routine in this loop
end repeat

to simply create a new folder if needed (no need to check if it exists):

do shell script "mkdir -p" & space & quoted form of (posix path of collectPaths & ":Old")

You have to be familiar with "quoted form" and "posix path", "posix file", HFS and POSIX paths. There are a lot of examples anywhere. You can browse StandardAdditions dictionary in the Script Editor's Library about these terms.

You have to figure out what's in the 'input' is it a list of paths, a path ? put "log input" , "log class of input", "log collectPaths" in your script at critical points to know more about what's going on.

Good luck..