"Can't get POSIX file" error from AppleScripts
I'm trying to write an InDesign script with AppleScript, I'm very new to AppleScripting(and Bash) and I'm struggling to find a way to accomplish a certain task. The goal of the InDesign script is to get all of the files in a group of directories and then export them as pdf. I'm able to get all of the files in a single directory like this
tell application "Finder"
set MyList to files of folder POSIX file "/Users/User/Desktop/Group-of-folders/folder-with-several-files" as alias list
end tell
repeat with aFile in MyList
tell application "Adobe InDesign CC 2019"
set fileName to do shell script "basename " & quoted form of (POSIX path of aFile) & "| cut -d. -f1"
set myDocument to open aFile
tell active document
export format PDF type to "/Users/User/Desktop/All PDF Exports" & fileName & ".pdf"
end tell
close active document saving no
end tell
end repeat
This works fine for just one folder but I would like the script to make a list of all the sub-directories inside the "Group-of-folders" and then repeat the above script inside each directory.
I've tried various combinations of the following and I keep getting the error "Can't get POSIX file \"/Users/user....?\"
tell application "Finder"
set myFolderList to folders of folder POSIX file "/Users/User/Desktop/Group-of-folders/" as alias list
repeat with aFolder in myFolderList
set filePath to (POSIX path of aFolder)
set MyList to files of folder POSIX file filePath as alias list
end repeat
end tell
error "Finder got an error: Can’t get POSIX file \"/Users/User/Desktop/Group-of-folders/Sub-folder-1/\"." number -1728 from file "Apple SSD:Users:User:Desktop:Group-of-folders:Sub-folder-1:"