By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,045 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,045 IT Pros & Developers. It's quick & easy.

How to get just the folder name for your current project

100+
P: 167
I am using currentProject.name (also CurDir) to get my full path name:
C:\Test\Test1\Folder

What I am wanting to do is to get the last part(folder) in the path, in this case 'folder'. I cannot find a function to get this. Am I overlooking it?

Thanks!
Feb 19 '09 #1
Share this Question
Share on Google+
4 Replies


100+
P: 365
Expand|Select|Wrap|Line Numbers
  1. Public Function FileNameFromPath(strFullPath As String) As String
  2.     FileNameFromPath = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath, "\"))
  3. End Function
  4.  
  5. Public Function FolderFromPath(strFullPath As String) As String
  6.     FolderFromPath = Left(strFullPath, InStrRev(strFullPath, "\"))
  7. End Function
  8.  
  9. Public Function FileExt(strFullPath As String) As String
  10.     FileExt = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath, "."))
  11. End Function
  12.  
eg
Expand|Select|Wrap|Line Numbers
  1. FileNameFromPath(CurrentDB.Name)
The other two may be useful too

Dan
Feb 19 '09 #2

DonRayner
Expert 100+
P: 489
This would work for you as well

Expand|Select|Wrap|Line Numbers
  1. strVar = CurrentProject.Path
  2. strFolder = Mid(strvar, InStrRev(strvar, "\") + 1)
Feb 19 '09 #3

NeoPa
Expert Mod 15k+
P: 31,419
Expand|Select|Wrap|Line Numbers
  1. Split(CurrentProject.Path, "\")(UBound(Split(CurrentProject.Path, "\")))
Alternatively (using CurrentDb.Name) :
Expand|Select|Wrap|Line Numbers
  1. Split(CurrentDb.Name, "\")(UBound(Split(CurrentDb.Name, "\")) - 1)
Feb 20 '09 #4

ADezii
Expert 5K+
P: 8,623
@ncsthbell
Just another alternative approach.

If I am reading this correctly, you wish to return the Name of the Last Folder in the Absolute Path to the actual Folder Name. If this is so:
  1. Pass the Absolute Path to the Folder to a Public Function.
  2. Within this Function, parse the individual elements of the Path into a Variant Array using the Split() Function.
  3. The Name of the Last Folder in the Path will be the Upper Bound of the Array.
    Expand|Select|Wrap|Line Numbers
    1. Public Function fExtractLastFolder(strPath As String)
    2. Dim varParse As Variant
    3.  
    4. varParse = Split(strPath, "\")
    5.  
    6. fExtractLastFolder = varParse(UBound(varParse))
    7. End Function
  4. Function Call:
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print "Last Folder in Path is ==> " & _
    2.             fExtractLastFolder("C:\Windows\System32\Plug Ins\Adapters")
  5. OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. Last Folder in Path is ==> Adapters
Feb 20 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.