Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compare 2 filepaths (String)

Posted on 1998-10-03
1
Medium Priority
?
293 Views
Last Modified: 2010-04-30

Hi, I have two filepaths and would like to compare in sort
that the following result is produced.

IE.
1 C:\Mary\MyFiles\Data\Graphics\file.tmp
2 C:\Mary\MyFiles\Upload\FTP\file.tmp

Result:
  \Upload\FTP\file.tmp

The idea is to compare number 2 with 1 and remove
folders that are the same.
Note: Without removeing the filename.

0
Comment
Question by:mary_idc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
jfayling earned 80 total points
ID: 1437934
here is an example of how to use this funciton!


MsgBox CompareFilePaths("C\Mary\MyFiles\Data\Graphics\file.tmp",_
"C:\Mary\MyFiles\Upload\FTP\file.tmp")




Function CompareFilePaths(ByVal strPath1 As String, ByVal strPath2 As String) As String

On Error GoTo CompareFilePathsError

Dim strNewPath As String
Dim lTotal1 As Long
Dim lTotal2 As Long
Dim varArray1 As Variant
Dim varArray2 As Variant
Dim i As Long
Dim j As Long

   
    lTotal1 = ParseString(strPath1, "\", varArray1)
    lTotal2 = ParseString(strPath2, "\", varArray2)
   
    i = 0
    j = 0
    strNewPath = ""
   
    Do
        If LCase$(CStr(varArray2(j))) <> LCase$(CStr(varArray1(j))) Then
            For i = j To lTotal2
                strNewPath = strNewPath + "\" + CStr(varArray2(i))
            Next
            Exit Do
        End If
        j = j + 1
    Loop Until j > lTotal2
   
    CompareFilePaths = strNewPath

    Exit Function
   
CompareFilePathsError:
    CompareFilePaths = ""

End Function


Function ParseString(LookIn As String, Search As String, ByRef ReturnArray As Variant) As Long
'
' Function Name:    ParseString
'
' Author:           JF Software (Jason R. Fayling)
'                   jfayling@glasscity.net
' Date:             1/10/97
'
' Inputs:           LookIn  (STRING)        String to use
'                   Search  (STRING)        What to look for in string
'                   ReturnARRAY (VARIANT)   Any found will be stored here
'
' Outputs:          ParseString (INTEGER)   Number of items in ReturnArray
'                                           starting with zero. If no item
'                                           was found, then returns -1
'
'                   ReturnArray (VARIANT)   Found items from string
'
' Purpose:          ParseString will take a string and seperate it into
'                   user-defined parts.
'                   Example:
'
'                       Dim i as Integer
'                       Dim j as integer
'                       dim Temp as variant
'
'                       i=ParseString("10/24/97","/",Temp)
'
'                       for j=0 to i
'                           msgbox Temp(j)
'                       next j
'
'                   This will display 10 then 24 then 97
'
'
' You are granted royalty free use of this code in your projects.   You may
' remove this comment block in your own projects.   If you intend to redistribute
' this function as part of a library or outside of your own VB project then you
' must leave this block in tact.


Dim X As Long
Dim start As Long
Dim pos As Long
Dim track As Long
ReDim TempHolder(Len(LookIn)) As String


    track = 0
    start = 1
   
    ' Start at the beginning of string and move down until it finds
    ' character it is looking for. Once it finds the character, it
    ' places everything before it and after the last found item into
    ' a new element in an array
   
    Do
        pos = InStr(start, LookIn, Search, vbBinaryCompare)
        If pos > 0 Then
            TempHolder(track) = Mid$(LookIn, start, (pos - start))
            track = track + 1
            start = pos + Len(Search)
        End If
    Loop Until pos = 0
   
    ' Make sure everything has been copied into Temp array
    TempHolder(track) = Mid$(LookIn, start, Len(LookIn))
       
    ReDim tempholder2(track)
   
    ' Move only elements with data in them
    For X = 0 To track
        tempholder2(X) = TempHolder(X)
    Next X
   
    Erase TempHolder
   
    ' Return Array is a variant so it can be passed an array
    ReturnArray = tempholder2
   
    If track = 0 Then
        ' Nothing was found
        ParseString = -1
    Else
        ParseString = track
    End If

End Function

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question