<?xml version="1.0"?>
<RBProject version="2006r1">
<block type="Module" ID="1799329351">
 <ObjName>RelativePath</ObjName>
 <ObjContainerID>0</ObjContainerID>
 <IsClass>0</IsClass>
 <IsInterface>0</IsInterface>
 <Compatibility></Compatibility>
 <Method>
  <ItemName>CreateRelativePath</ItemName>
  <Compatibility></Compatibility>
  <Visible>1</Visible>
  <ItemSource>
   <TextEncoding>134217984</TextEncoding>
   <SourceLine>Function CreateRelativePath(extends fromFile as FolderItem, toFile as FolderItem) As String</SourceLine>
   <SourceLine>if not fromFile.Directory then</SourceLine>
   <SourceLine>fromFile = fromFile.Parent</SourceLine>
   <SourceLine>end if</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>// Get a list of path parts by looping until the parent is nil.</SourceLine>
   <SourceLine>dim tmpf as FolderItem</SourceLine>
   <SourceLine>dim fromPathParts() as String</SourceLine>
   <SourceLine>dim toPathParts() as String</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>tmpf = fromFile</SourceLine>
   <SourceLine>while tmpf &lt;&gt; nil</SourceLine>
   <SourceLine>fromPathParts.Append tmpf.Name</SourceLine>
   <SourceLine>tmpf = tmpf.Parent</SourceLine>
   <SourceLine>wend</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>tmpf = toFile</SourceLine>
   <SourceLine>while tmpf &lt;&gt; nil</SourceLine>
   <SourceLine>toPathParts.Append tmpf.Name</SourceLine>
   <SourceLine>tmpf = tmpf.Parent</SourceLine>
   <SourceLine>wend</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>// If the top-level items don't match, we're on different volumes, and that ain't going to work</SourceLine>
   <SourceLine>if fromPathParts( ubound( fromPathParts ) ) &lt;&gt; toPathParts( ubound( toPathParts ) ) then</SourceLine>
   <SourceLine>return ""</SourceLine>
   <SourceLine>end if</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>// Now, remove each of the common items from the tops of both arrays.</SourceLine>
   <SourceLine>while ubound( fromPathParts ) &gt;= 0 and ubound( toPathParts ) &gt;= 0 _</SourceLine>
   <SourceLine>and fromPathParts( ubound( fromPathParts ) ) = toPathParts( UBound( toPathParts ) )</SourceLine>
   <SourceLine>fromPathParts.Remove( UBound( fromPathParts ) )</SourceLine>
   <SourceLine>toPathParts.Remove( UBound( toPathParts ) )</SourceLine>
   <SourceLine>wend</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>// Now, for every "from" path part that's remaining, it's one level we must go up.</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>dim relativePathParts() as String</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>if UBound( fromPathParts ) &lt; 0 then</SourceLine>
   <SourceLine>// Just operate on the current directory</SourceLine>
   <SourceLine>relativePathParts.Append kSameDirPath</SourceLine>
   <SourceLine>else</SourceLine>
   <SourceLine>for i as integer = 0 to UBound( fromPathParts )</SourceLine>
   <SourceLine>relativePathParts.Append kUpDirPath</SourceLine>
   <SourceLine>next</SourceLine>
   <SourceLine>end if</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>// Now that we're up to the same parent folder, we need to traverse down into</SourceLine>
   <SourceLine>// each "toPathPart"</SourceLine>
   <SourceLine>while UBound( toPathParts ) &gt;= 0</SourceLine>
   <SourceLine>relativePathParts.Append toPathParts.Pop</SourceLine>
   <SourceLine>wend</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>// Finally, return the result</SourceLine>
   <SourceLine>return join( relativePathParts, kPathSeparator )</SourceLine>
   <SourceLine>End Function</SourceLine>
  </ItemSource>
  <TextEncoding>134217984</TextEncoding>
  <AliasName></AliasName>
  <ItemFlags>0</ItemFlags>
  <IsShared>0</IsShared>
  <ItemParams>extends fromFile as FolderItem, toFile as FolderItem</ItemParams>
  <ItemResult>String</ItemResult>
 </Method>
 <Method>
  <ItemName>ResolveRelativePath</ItemName>
  <Compatibility></Compatibility>
  <Visible>1</Visible>
  <ItemSource>
   <TextEncoding>134217984</TextEncoding>
   <SourceLine>Function ResolveRelativePath(extends fromFile as FolderItem, path as String) As FolderItem</SourceLine>
   <SourceLine>if not fromFile.Directory then fromFile = fromFile.Parent</SourceLine>
   <SourceLine>// Split the path parts and operate on the parts</SourceLine>
   <SourceLine>dim outf as FolderItem = fromFile</SourceLine>
   <SourceLine>dim pathParts() as String = Split( path, kPathSeparator )</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>for i as integer = 0 to UBound( pathParts )</SourceLine>
   <SourceLine>if outf = nil then exit</SourceLine>
   <SourceLine>if pathParts(i) = kUpDirPath then</SourceLine>
   <SourceLine>outf = outf.Parent</SourceLine>
   <SourceLine>elseif pathParts(i) = kSameDirPath then</SourceLine>
   <SourceLine>// Nothing, stay the same</SourceLine>
   <SourceLine>else</SourceLine>
   <SourceLine>outf = outf.Child( pathParts(i) )</SourceLine>
   <SourceLine>end if</SourceLine>
   <SourceLine>next</SourceLine>
   <SourceLine></SourceLine>
   <SourceLine>return outf</SourceLine>
   <SourceLine>End Function</SourceLine>
  </ItemSource>
  <TextEncoding>134217984</TextEncoding>
  <AliasName></AliasName>
  <ItemFlags>0</ItemFlags>
  <IsShared>0</IsShared>
  <ItemParams>extends fromFile as FolderItem, path as String</ItemParams>
  <ItemResult>FolderItem</ItemResult>
 </Method>
 <ViewBehavior>
  <ViewProperty>
   <ObjName>Name</ObjName>
   <Visible>1</Visible>
   <PropertyGroup>ID</PropertyGroup>
  </ViewProperty>
  <ViewProperty>
   <ObjName>Index</ObjName>
   <Visible>1</Visible>
   <PropertyGroup>ID</PropertyGroup>
   <PropertyValue>-2147483648</PropertyValue>
  </ViewProperty>
  <ViewProperty>
   <ObjName>Super</ObjName>
   <Visible>1</Visible>
   <PropertyGroup>ID</PropertyGroup>
  </ViewProperty>
  <ViewProperty>
   <ObjName>Left</ObjName>
   <Visible>1</Visible>
   <PropertyGroup>Position</PropertyGroup>
   <PropertyValue>0</PropertyValue>
  </ViewProperty>
  <ViewProperty>
   <ObjName>Top</ObjName>
   <Visible>1</Visible>
   <PropertyGroup>Position</PropertyGroup>
   <PropertyValue>0</PropertyValue>
  </ViewProperty>
 </ViewBehavior>
 <Constant>
  <TextEncoding>134217984</TextEncoding>
  <ItemName>kUpDirPath</ItemName>
  <ItemType>0</ItemType>
  <ItemDef>..</ItemDef>
  <ItemFlags>33</ItemFlags>
 </Constant>
 <Constant>
  <TextEncoding>134217984</TextEncoding>
  <ItemName>kSameDirPath</ItemName>
  <ItemType>0</ItemType>
  <ItemDef>.</ItemDef>
  <ItemFlags>33</ItemFlags>
 </Constant>
 <Constant>
  <TextEncoding>134217984</TextEncoding>
  <ItemName>kPathSeparator</ItemName>
  <ItemType>0</ItemType>
  <ItemDef>:</ItemDef>
  <ItemFlags>33</ItemFlags>
 </Constant>
</block>
</RBProject>
