Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Get Relative Path

Featured Replies

I'm looking for a function that will generate a relative path from one file path to another. for example:

GetRelativePath ( "\\TYPELEVEN-HOME\backups\pls\test.wpl" ; "\\TYPELEVEN-HOME\backups\pls\LogMeIn.msi" ) = "LogMeIn.msi"

GetRelativePath ( "\\TYPELEVEN-HOME\backups\pls\test.wpl" ; "\\TYPELEVEN-HOME\backups\pls\New folder\LogMeIn.msi" ) = "New folder\LogMeIn.msi"

GetRelativePath ( "\\TYPELEVEN-HOME\backups\pls\test.wpl" ; "\\TYPELEVEN-HOME\backups\DP0304P.exe" ) = "..\DP0304P.exe"

GetRelativePath ( "\\TYPELEVEN-HOME\backups\pls\test.wpl" ; "\\TYPELEVEN-HOME\Done\Software\cr-1nb03.zip" ) = "..\..\Done\Software\cr-1nb03.zip"

Anyone seen a function like this?

Anyone seen a function like this?

I haven't, but it shouldn't be very difficult to construct. Roughly:

Compare the first directory of both paths; if they are the same, remove the first directory from both and call the function again. Otherwise count the remaining directories in the source path, and tack as many "../" in front of the target path.

  • Author

I think I figured it out. Hows this one look? Can you think of anything that would mess this one up?

GetReletivePath ( from ; to )

Case(



IsEmpty($i) ; Let($i = 1 ; GetReletivePath(from ; to));



Left(from;$i) = Left(to;$i) ;  Let($i = $i + 1 ; GetReletivePath(from ; to));



Let([

fromRemainder = Middle(from;$i;Length(from));

toRemainder =  Middle( to;$i - 1 ;Length(to) );

posOfFirsttSlash =  Position (   toRemainder ; "\\" ; 1; 1);

toRemainder =  Middle( to ; $i + posOfFirsttSlash - 1  ; Length(to) );

slashes = Substitute (Filter (  fromRemainder; "\\")  ; "\\"; "..\\" );

$i = ""

];

slashes & toRemainder

)

)

Also is there a good explanation of how local variables behave in custom functions?

I think that checking identity character-by-character is inefficient, compared to checking directory-by-directory.

Moreover, it creates a problem when two corresponding directories start with the same character/s. For example, given:

from = "\\NET\dir\ab\source.txt"

to = "\\NET\dir\abc\target.txt"

your function returns:

"..\target.txt"

while IMHO the correct result is:

"..\abc\target.txt"

I would do it this way:

http://www.briandunning.com/cf/1251

  • Author

I would do it this way:

http://www.briandunning.com/cf/1251

Thanks!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.