Help with POSIX File/Folder Paths



I’m modifying a large existing script. The Script does a lot of File Munging and passes things around as POSIX file/folder paths.

I haven’t done any AppleScript in a very long time and I don’t have access to my past work.

I know I have done this before but I just can’t remember what the trick is!

Basically I want  to scan a Folder and check if:

There is a file with a “.to2” (or specified) extension and if so, check if there is also a folder of the same name and if there is, add the Full POSIX file path to one list and the Full POSIX Folder path to another.

So, if we have a base folder of " /Users/xxxxxxxx/Desktop/Dave's Mock Folder/, my functions get passed this Folder string.

If it contained the Following files:
Test1      (Folder)
Test4    (Folder)

then return should be:

myFileList: Test1.txt, Test4.txt
myFolderList: Test1,Test4

I’ve got it to almost work in test form below, but the check for the existence of the folder always report true - see comment below.

Any help greatly appreciated!

tell application "Finder"
set mySaveASDelimiters to AppleScript's text item delimiters
set myScriptFilePath to (path to me)
set mySourceFolder to folder of myScriptFilePath
set mySourceFolderPathString to mySourceFolder as string
set myPOSIXSourceFolder to my POSIX path of mySourceFolderPathString
log "myScriptFilePath: [" & myScriptFilePath & "]"
log "mySourceFolder: [" & mySourceFolder & "]"
log "mySourceFolderPathString: [" & mySourceFolderPathString & "]"
log "myPOSIXSourceFolder: [" & myPOSIXSourceFolder & "]"
set myFileAliasList to the entire contents of mySourceFolder
log "-----"
set myTP2FileList to {}
set myTP2FolderList to {}
repeat with myFile in myFileAliasList
set myTemp to properties of myFile
set myFileName to name of myFile
if (myFileName starts with "setup-") and (myFileName ends with ".tp2") then
set AppleScript's text item delimiters to "."
set myTP2FolderName to first text item of myFileName
set AppleScript's text item delimiters to "-"
set myTP2FolderName to last text item of myTP2FolderName
set AppleScript's text item delimiters to mySaveASDelimiters
set myTP2FolderPath to myPOSIXSourceFolder & myTP2FolderName as string
log "myTP2FolderPath: " & myTP2FolderPath

The (exists folder myTP2FolderPath) ALWAYS return true, e.g. I never get a beep/dialog
tell application "System Events"
if not (exists folder myTP2FolderPath) then
display dialog "Could not find Mod folder for Mod: " & myTP2FolderName
return {}
end if
end tell
log "myFileName: " & myFileName
log "myTP2FolderName: " & myTP2FolderName
set end of myTP2FileList to myFileName
set end of myTP2FolderList to myTP2FolderName
end if
end repeat
log "-----"
log "myTP2FileList: " & myTP2FileList
log "myTP2FolderList: " & myTP2FolderList
return myTP2FileList
end tell

Join to automatically receive all group messages.