Date
1 - 3 of 3
Help with POSIX File/Folder Paths
Dave
Hi, 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.txt Test1 (Folder) Test2.txt Test3.txt Test4.txt 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! Thanks Dave 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 beep 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 |
|
Dave
Opps, found a typeo: Folder actually looks like this: Test1.tp2 Test1 (Folder) Test2.tp2 Test3.tp2 Test4.tp2 Test4 (Folder) and the return should be: myFileList: Test1.tp2, Test4.tp2 myFolderList: Test1,Test4
|
|
Dave
I posted this a few days ago, I’ve sorted it out now, took a while for my brain to re-enter AppleScript Mode!
toggle quoted message
Show quoted text
|
|