Created
January 8, 2015 16:07
-
-
Save craibuc/8ff2cf5aad43576bf247 to your computer and use it in GitHub Desktop.
SplitPath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Purpose: Converts a path to a list | |
-- Parameters: | |
-- thePath - text - format Users:craibuc:Desktop:foobar.txt | |
-- Returns: List | |
-- Usage: | |
-- on splitPath("Users:craibuc:Desktop:Output:data.xlsx") | |
-- (*thePath:Users, craibuc, Desktop, Output, data.xlsx, theFile:foobar.txt theName:foobar, theExtension:txt*) | |
-- | |
on splitPath(theFilePath) | |
-- empty list | |
set theList to {thePath:"", theFile:"", theName:"", theExtension:""} | |
-- save delimiters to restore old settings | |
set oldDelimiters to AppleScript's text item delimiters | |
-- segment text by ':' | |
set text item delimiters to ":" | |
-- calculate 'thePath' | |
set thePath of theList to (text items 1 thru -2 of theFilePath) | |
-- calculate 'theFile' | |
set theFile of theList to (last text item of theFilePath) | |
-- calculate 'theName' and 'theExtension' | |
set temp to last text item of theFilePath | |
-- segment text by '.' | |
set text item delimiters to "." | |
set theName of theList to (text item 1 of temp as text) | |
set theExtension of theList to (text item 2 of temp as text) | |
-- restore the old setting | |
set AppleScript's text item delimiters to oldDelimiters | |
return theList | |
end splitPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment