Skip to content

Instantly share code, notes, and snippets.

@mavnn
Last active December 14, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavnn/5109283 to your computer and use it in GitHub Desktop.
Save mavnn/5109283 to your computer and use it in GitHub Desktop.
Fun with relative directories...
let GetHintPath hintPathFromRoot root projFile =
let rootDir = DirectoryInfo(root)
let projDir = DirectoryInfo(Path.GetDirectoryName(projFile))
let rec dirDiff (rootDir : DirectoryInfo) (currentDir : DirectoryInfo) levels =
if rootDir.FullName = currentDir.FullName then
levels
else
dirDiff rootDir (currentDir.Parent) (levels + 1)
hintPathFromRoot::[for _ in 1..(dirDiff rootDir projDir 0) -> ".."]
|> List.rev
|> List.fold (@@) "."
@mavnn
Copy link
Author

mavnn commented Mar 7, 2013

This code is completely untested, so don't rely on it to actually work.

@@ is a custom operator for Path.Combine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment