Using automator and AppleScript to move a file to a different folder and subfolder based on name and content of a file

applescriptautomatorfinderpdf

I'm a total newbie on Automator and Scripting… I have read a lot of answers to problems a bit similar to mine, but I don't succeed to adapt with Automator + AppleScript.

Here is what I want to do:

When I download a file to a directory /Volumes/Macboot /Downloads, (yes there is a space in the HDD's name), e.g. statement_EUR_2020-05-01_2020-05-31.pdf.

I verify if the file is with extension pdf + it contains an IBAN + the name contains "statement".
filter for the document

If the file corresponds, I want to verify the year and month in the name and move it accordingly to the good Google Drive folder:

/Volumes/Macboot /Travail en cours/Google
Drive/Company/Comptabilité/2020/05/Compte Transferwise 1/

With help from @Solar Mike, here is what I'm attempting:
What I am doing without success right now:

on run {input, parameters}
    tell application "Finder"
        activate
        set theFile to input as text
        set copyFile to input as alias
        set yearName to ((characters 34 thru -1 of theFile) as string) --trim first 35
        set yearName to ((characters 1 thru -22 of yearName) as string) --trim last 23
        set monthName to ((characters 39 thru -1 of theFile) as string)
        set monthName to ((characters 1 thru -19 of monthName) as string)
        set destinationFolder to ("Macboot :Travail en cours:Google Drive:Company:Comptabilité:" & yearName & ":" & monthName & ":Compte Transferwise 1:Relevé PDF + fichier CSV:" as alias)
        copy copyFile to (destinationFolder) 
    end tell
end run

No error… but no copied file.
yearName is good, as is monthName and destinationFolder, but perhaps I don't use the good method to copy?

Best Answer

I used this:

tell application "Finder"
activate
        set source_folder to choose folder with prompt "Please choose the Source-Folder:" default location ((path to home folder) as alias)
        set source_files to every file in source_folder
        set target_folder to choose folder with prompt "Please choose the Taget-Folder:" default location (":Applications:" as alias)
        repeat with i from 1 to number of items in source_files
                set source_file to (item i of source_files)
                copy source_file to (target_folder) -- use "copy source_file to folder (target_folder as alias)" to copy the files
        end repeat
        set question to display dialog "  Files have  been moved.
end tell