Topics

relative paths etc...

Jean-Christophe Helary <jean.christophe.helary@...>
 

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
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com

Shane Stanley
 

On 27 Dec 2017, at 8:59 pm, Jean-Christophe Helary <jean.christophe.helary@...> wrote:

I just want to know if there is a way to accomplish that that does not involve weird (path as string) manipulations...

I guess it depends on your definition of weird.

set fullPath to "/path/to/folder/path/from/folder/file"
set rootPath to "/path/to/folder"
set relpath to "." & text ((length of rootPath) + 1) thru -1 of fullPath


Jean-Christophe Helary <jean.christophe.helary@...>
 

On Dec 27, 2017, at 20:56, Shane Stanley <sstanley@...> wrote:

On 27 Dec 2017, at 8:59 pm, Jean-Christophe Helary <jean.christophe.helary@...> wrote:

I just want to know if there is a way to accomplish that that does not involve weird (path as string) manipulations...
I guess it depends on your definition of weird.

set fullPath to "/path/to/folder/path/from/folder/file"
set rootPath to "/path/to/folder"
set relpath to "." & text ((length of rootPath) + 1) thru -1 of fullPath
That pretty much fits my definition :)

But thank you. I'll see which of your approach and Yves is easier to fit in my code and will probably come back here for further hints.

In the meanwhile, I hope you all have nice holidays.

Jean-Christophe Helary
-----------------------------------------------
@brandelune http://mac4translators.blogspot.com