Getting filename out of fully qualified path 
Author Message
 Getting filename out of fully qualified path

How do get the 'path' and 'filename' parts of a fully qualified path.
Ex.
For c:\data\access\file.mdb

I would like a function that returns:
c:\data\access\

And another that returns:
file.mdb

Is there an easy way to do this or do I have to write my own code?

--
Please respond to the newsgroup AND the author:

Thanks
Shawn



Mon, 10 Dec 2001 03:00:00 GMT  
 Getting filename out of fully qualified path
Take a look to the General section in the Dev's site:

http://home.att.net/~dashish/

--
Alberto Borbolla
Microsoft VB MVP
Tecnologia en Sistemas Mexico


Quote:
> How do get the 'path' and 'filename' parts of a fully qualified path.
> Ex.
> For c:\data\access\file.mdb

> I would like a function that returns:
> c:\data\access\

> And another that returns:
> file.mdb

> Is there an easy way to do this or do I have to write my own code?

> --
> Please respond to the newsgroup AND the author:

> Thanks
> Shawn



Mon, 10 Dec 2001 03:00:00 GMT  
 Getting filename out of fully qualified path
Everyone tells you to use Dir(~~) functions... not much use if you are
coding a 'Save' operation, and the file (or even the target directory)
don't exist yet!

TAke a look at these three string-handling functions. Apologies for the
Variable-naming convention - and for the fact that they are heavily
'coupled' - you need all three of them, or they don't work:

Function funcDirFromFullPath(ByVal strFullName As String) As String
On Error GoTo ERRfuncDirFromFullPath
 'Returns the dir part of a full dos path
 'Dir(MyString) doesn't work if file strFullName doesn't exist yet...
as in SaveAs operations

funcDirFromFullPath = ""

funcDirFromFullPath = Left(strFullName, Len(strFullName) - Len
(funcFileFromFullPath(strFullName)))

EXITfuncDirFromFullPath:
    Exit Function
ERRfuncDirFromFullPath:
    funcDirFromFullPath = ""
    Resume EXITfuncDirFromFullPath
End Function

Function funcFileFromFullPath(ByVal strFullName As String) As String
On Error GoTo ERRfuncFileFromFullPath
 'Returns the filename part of a full dos path
 'Dir(MyString) doesn't work if file strFullName doesn't exist yet...
as in SaveAs operations

funcFileFromFullPath = ""

        'extract file name by string manipulation... find the last
occurrence of backslash
        strFullName = funcReverseString(strFullName)
        strFullName = Left(strFullName, InStr(strFullName, "\") - 1)

        funcFileFromFullPath = funcReverseString(strFullName)

        'strDataSaveDir = Left(strDataSaveFullName, Len
(strDataSaveFullName) - Len(strDataSaveFile) - 1)

EXITfuncFileFromFullPath:
    Exit Function
ERRfuncFileFromFullPath:
    funcFileFromFullPath = ""
    Resume EXITfuncFileFromFullPath
End Function

Function funcReverseString(ByVal MyString As String) As String
On Error GoTo ERRfuncReverseString

Dim StringReversed As String
Dim MyStringLength As Integer
Dim i As Integer

funcReverseString = ""

MyStringLength = Len(MyString)

For i = 1 To MyStringLength
    StringReversed = Mid(MyString, i, 1) & StringReversed
Next i

funcReverseString = StringReversed

EXITfuncReverseString:
    Exit Function
ERRfuncReverseString:
    funcReverseString = ""
    Resume EXITfuncReverseString
End Function

Regards - Nigel Heffernan

For Demonstration purposes only. Code is provided 'As-Is' entirely
without warranty and no liability is accepted for any loss or damage
arising from its use, howsoever caused. In incorporating this code into
a live application you undertake full responsibility for testing and
all liabilities arising from its use in that application.



Quote:
> How do get the 'path' and 'filename' parts of a fully qualified path.
> Ex.
> For c:\data\access\file.mdb

> I would like a function that returns:
> c:\data\access\

> And another that returns:
> file.mdb

> Is there an easy way to do this or do I have to write my own code?

> --
> Please respond to the newsgroup AND the author:

> Thanks
> Shawn

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


Tue, 11 Dec 2001 03:00:00 GMT  
 Getting filename out of fully qualified path

Quote:
>How do get the 'path' and 'filename' parts of a fully qualified path.
>Ex.
>For c:\data\access\file.mdb

>I would like a function that returns:
>c:\data\access\

>And another that returns:
>file.mdb

>Is there an easy way to do this or do I have to write my own code?

I think you need to roll your own.

Something like :

<AIRCODE>

intPosition = Len(strFullPath)

Loop Until Mid$(strFullPath,intPosition,1) = "\"
intPosition = intPosition - 1
next

strPath = Left$(strFullPath,intPosition)
strFileName = Right(strFullPath, intPosition +1

</AIRCODE>

I've almost certainly got some errors here, but I'm late for work and
you should get the idea.
--
Albert Marshall



Tue, 11 Dec 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Parsing an HTML Document - Change Relative paths to fully qualified paths

2. Creating relative directory path given fully-qualified path

3. getting just the filename, not the filename path from the opendialog control

4. All programmers - Fully qualify your references

5. Invalid URL form or fully-qualified absolute URL was used

6. Get Registered Fully Qualified File Name Using GUID

7. Getting path/filename only from wdDialogFileOpen Dialog

8. Getting current task filename/path

9. Getting filename/path of Win95 foreground task

10. getting a filename from a path

11. Absolute FileName Path

12. Retrieving Full path and Filename vs Open Dialog Box

 

 
Powered by phpBB® Forum Software