Re: file path problem
Re: file path problem
- Subject: Re: file path problem
- From: Cameron Knowlton <email@hidden>
- Date: Fri, 01 Jul 2011 14:46:30 -0700
You're seeing other forums? I thought we were exclusive. Who is she?!?
Cameron Knowlton
At 1:01 PM -0700 11/07/01, Ron Hunsinger wrote:
>On Jul 1, 2011, at 6:35 AM, Michelle Steiner wrote:
>
>> On Jul 1, 2011, at 3:06 AM, Jean-Christophe Helary wrote:
>>
>>> My biggest problem with Applescript for now is file paths. I just can't wrap my mind around the way they are handled...
>>
>> In what way? Personally, I prefer to use the traditional colon-separated path names; that eliminates any problems with POSIX conversions.
>
>Exactly!
>
>In some of the other AppleScript forums I participate in, I frequently see (and post corrections to) bugs in posted AppleScripts. I've noticed a recurring theme to many of these bugs: they convert prematurely to POSIX notation. I often find that I can remove the bugs AND make the code shorter AND easier to read if I do all filepath manipulations in the HFS-style notation (with colon-separated paths), and only convert to POSIX (by invoking quoted form of POSIX path of ...) at the very last moment before going to POSIX-land (for example, for do shell script ...).
>
>One common gotcha that comes from premature conversion to POSIX is the temptation to concatenate a POSIX path with an HFS path. For example:
>
> set dir to POSIX path of ...
> tell application Finder
> repeat with aName in name of every ...
> set itsPath to dir & "/" & aName
> ...
>
>At that moment, "dir" is POSIX-style, but "aName" is HFS-style. Sure, it's a single name, which seems like it oughta be the same either way, but what if aName is "Agenda for 12/7"? Slashes are path separators in POSIX, but not in HFS, and the concatenation produces a mess that contains slashes of both forms.
>
>Keep everything in HFS-style strings (or aliases or something else coercible to strings), do all your concatenations in that form, and let one final call to POSIX path of ... turn all those non-path-separating slashes into colons at the same time as its turning the path-separating colons into slashes.
--
Cameron Knowlton
KnowledgeVine SEO Dashboards
email@hidden
P: 250.382.0226
http://www.knowledgevine.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden