Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

STrip path of a file

Discussion in 'Information Technology' started by SF, Jul 28, 2006.

Tags:
  1. SF

    SF
    Expand Collapse
    Guest

    Hi,

    I have file eg G:\MYPICTURES\123456.JPG

    What is the function to strip the PATH (eg G:\MYPICTURES\) out of the enture
    string?

    SF
     
  2. Loading...


  3. strive4peace

    strive4peace
    Expand Collapse
    Guest

    If the file exists, you can do this:

    '~~~~~~~~~~~~~
    dim mPath as string, mFile as string
    dim mSpec as string

    mSpec = "G:\MYPICTURES\123456.JPG"

    mFile = DIR(mSpec)

    mPath = left(mSpec, _
    len(mSpec)-len(mfile))
    '~~~~~~~~~~~~~


    if you do not know if the file exists...

    '~~~~~~~~~~~~~
    Function GetPath( _
    pSpec as string) _
    as String

    dim mPath as string, i as integer

    i = len(mSpec)

    for i = len(mSpec) to 1 step -1
    if mid(pSpec,i,1) = "\") then
    GetPath = _
    left(pSpec, i)
    exit function
    end if
    next i

    End Function

    '~~~~~~~~~~~~~


    Warm Regards,
    Crystal
    Microsoft Access MVP 2006

    *
    Have an awesome day ;)

    remote programming and training
    strive4peace2006 at yahoo.com

    *

    SF wrote:
    > Hi,
    >
    > I have file eg G:\MYPICTURES\123456.JPG
    >
    > What is the function to strip the PATH (eg G:\MYPICTURES\) out of the enture
    > string?
    >
    > SF
    >
    >
     
  4. Steve Schapel

    Steve Schapel
    Expand Collapse
    Guest

    SF,

    Mid([YourField],InStrRev([YourField],"\")+1)

    --
    Steve Schapel, Microsoft Access MVP

    SF wrote:
    > Hi,
    >
    > I have file eg G:\MYPICTURES\123456.JPG
    >
    > What is the function to strip the PATH (eg G:\MYPICTURES\) out of the enture
    > string?
    >
    > SF
    >
    >
     
  5. Dirk Goldgar

    Dirk Goldgar
    Expand Collapse
    Guest

    "SF" <socfund@online.com.kh> wrote in message
    news:euh0073hGHA.1864@TK2MSFTNGP02.phx.gbl
    > Hi,
    >
    > I have file eg G:\MYPICTURES\123456.JPG
    >
    > What is the function to strip the PATH (eg G:\MYPICTURES\) out of the
    > enture string?


    If the file exists, you can use this simple function:

    '----- start of code -----
    Function PathOnly(FullFilePath As String) As String

    PathOnly = _
    Left(FullFilePath, _
    Len(FullFilePath) - Len(Dir(FullFilePath)))

    End Function

    '----- end of code -----

    If the file doesn't exist, you need to do a bit more work:

    '----- start of code #2 -----
    Function PathOnly2(FullFilePath As String) As String

    'Use this version if the file may not exist.

    Dim I As Long

    I = InStrRev(FullFilePath, "\")

    If I = 0 Then
    I = InStrRev(FullFilePath, ":")
    End If

    If I = 0 Then
    PathOnly2 = FullFilePath
    Else
    PathOnly2 = Left(FullFilePath, I)
    End If

    End Function
    '----- end of code #2 -----

    --
    Dirk Goldgar, MS Access MVP
    www.datagnostics.com

    (please reply to the newsgroup)
     
  6. strive4peace

    strive4peace
    Expand Collapse
    Guest

    thanks, Steve ... forgot about InStrRev ... old habits die hard!


    Warm Regards,
    Crystal
    Microsoft Access MVP 2006

    *
    Have an awesome day ;)

    remote programming and training
    strive4peace2006 at yahoo.com

    *

    Steve Schapel wrote:
    > SF,
    >
    > Mid([YourField],InStrRev([YourField],"\")+1)
    >
     
  7. Steve Schapel

    Steve Schapel
    Expand Collapse
    Guest

    Well, looks like I may have misinterpreted your question. I assumed
    that after a "strip", the interest is more on what's left rather than on
    what's removed ;-). In any case, even with my interpretation, a simple
    Dir([YourField]) would have sufficed. Oh well...

    --
    Steve Schapel, Microsoft Access MVP


    Steve Schapel wrote:
    > SF,
    >
    > Mid([YourField],InStrRev([YourField],"\")+1)
    >
     
  8. strive4peace

    strive4peace
    Expand Collapse
    Guest

    Hi Steve,

    you're not the only one ;) ... now that you mention it, the
    question could be interpreted 2 ways...


    Warm Regards,
    Crystal
    Microsoft Access MVP 2006

    *
    Have an awesome day ;)

    remote programming and training
    strive4peace2006 at yahoo.com

    *

    Steve Schapel wrote:
    > Well, looks like I may have misinterpreted your question. I assumed
    > that after a "strip", the interest is more on what's left rather than on
    > what's removed ;-). In any case, even with my interpretation, a simple
    > Dir([YourField]) would have sufficed. Oh well...
    >
     
  9. RoyVidar

    RoyVidar
    Expand Collapse
    Guest

    SF wrote in message <euh0073hGHA.1864@TK2MSFTNGP02.phx.gbl> :
    > Hi,
    >
    > I have file eg G:\MYPICTURES\123456.JPG
    >
    > What is the function to strip the PATH (eg G:\MYPICTURES\) out of the
    > enture string?
    >
    > SF


    For the fun of it, having a bit of flexibility:

    Dim strDrive As String
    Dim strDir As String
    Dim strFile As String
    Dim strExt As String

    Const cstrFullName As String = _
    "G:\MYPICTURES\123456.JPG"

    With WizHook
    .Key = 51488399
    .SplitPath cstrFullName, strDrive, strDir, strFile, strExt
    Debug.Print strDrive, strDir, strFile, strExt
    End With

    --
    Roy-Vidar
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page