• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: relative paths etc...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: relative paths etc...


  • Subject: Re: relative paths etc...
  • From: Yvan KOENIG <email@hidden>
  • Date: Wed, 27 Dec 2017 11:35:27 +0100


> Le 27 déc. 2017 à 10:59, Jean-Christophe Helary
> <email@hidden> a écrit :
>
> I seem to be wasting a lot of time on something that may already exist...
>
> I'm trying to find a way to add/subtract paths to files.
>
> Like, I have a path from / and I want to subtract it from the path to a given
> file so that I end up with a path relative to the end of the first path.
> Sorry it it's not clear:
>
> original path:
>       /path/to/folder
>
> path to subtract it from:
>       /path/to/folder/path/from/folder/file
>
> result:
>       ./path/from/folder/file
>
> the idea being that I need to cd to the shortest path and work on the files
> *relative to that position*.
>
> I just want to know if there is a way to accomplish that that does not
> involve weird (path as string) manipulations...
>
> (I spent the whole morning fighting with the "a reference to" and I'm still
> bleeding)
>
> Jean-Christophe Helary


If I understand well you may use :

set fullPath to "/path/to/folder/path/from/folder/file"
set rootPath to "/path/to/folder"
set relativePath to my supprime(fullPath, rootPath) --> "/path/from/folder/file"


#=====
(*
removes every occurences of d in text t
*)
on supprime(t, d)
        local oTIDs, l
        set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, d}
        set l to text items of t
        set AppleScript's text item delimiters to ""
        set t to l as text
        set AppleScript's text item delimiters to oTIDs
        return t
end supprime

#=====


Yvan KOENIG running High Sierra 10.13.2 in French (VALLAURIS, France) mercredi
27 décembre 2017 11:35:11




 _______________________________________________
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

  • Follow-Ups:
    • Re: relative paths etc...
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >relative paths etc... (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: relative paths etc...
  • Next by Date: Re: relative paths etc...
  • Previous by thread: relative paths etc...
  • Next by thread: Re: relative paths etc...
  • Index(es):
    • Date
    • Thread