LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA compare two file paths and delete common root

I need a method for comparing two file paths and removing the common root.
Specifically, I want to create a relative path from one file to another.

I do not know in advance what the file path is or how long it is. The files
may be of different types. A typical example might be:

Path1 = S:\Workgroups\Engineering\Graphics\Pictures\Overvi ew.bmp

Path2 = S:\Workgroups\Engineering\Trends\Spreadsheet.xls

Path3 = S:\Workgroups\Engineering\Graphics\Pictures\Sheets \Report.doc

I want to set Path1 to be the "home" location. The relative path for Path1
in my example would be:

.\Overview.bmp

The relative path from Path1 to Path2 would be:

...\Trends\Spreadsheet.xls

The relative path from Path1 to Path3 would be:

.\Sheets\Report.doc


First, I need to identify the common root. In my example, the common root is:

S:\Workgroups\Engineering\

Second, I need to replace my "Home" path path with ".\filename.ext"
In my example, I need to change my "Home" path to ".\Overview.bmp"

Third, I need to know if the path being compared is in a folder up or down
from the "home" file.

Replace EACH FOLDER ONE LEVEL UP from my "home" file with a "."

I need to replace EACH FOLDER ONE LEVEL DOWN from my "home" file -or- from
the common root with the name of the folder.

I have played with various versions of the split function, LEN(), INSTR(),
INSTREV(), LEFT(), RIGHT(), MID(), vbTextCompare, etc. without success. I
can get the full file and path name without a problem an create the "Home"
file name. It's the comparison that is tripping me up.

Any help you could provide would be greatly appreciated.

Susan Forson


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i compare and remove common names from 2 excel work sheets Andrew Excel Worksheet Functions 0 April 8th 10 09:02 AM
Compare two worksheets and identify common entries MarkT Excel Discussion (Misc queries) 3 November 8th 07 01:09 AM
Compare two wk sheets with common data using copy paste macro conejo Excel Worksheet Functions 0 October 8th 07 09:21 AM
excel file paths Jane Excel Discussion (Misc queries) 1 August 17th 06 04:59 PM
file paths hr Excel Discussion (Misc queries) 0 December 7th 05 04:59 PM


All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"