UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Instrrev To Return The Last Folder In A Path, Access 2010    
 
   
m1citylad
post Nov 14 2017, 08:50 AM
Post#1



Posts: 51
Joined: 7-April 08



Hi, I want a field in a query that has the last folder name of a path, I have the path in a field called "Folder"

Eg \\MyServer\MyDepartment\MyTeamsFolder\MyPersonalFolder\MyPictures\

The length of paths adn depth of folers will vary so I'm trying to use teh 2nd to last "\" to return the folder name.

I want the code to return "\MyPictured\" or "MyPictures" I dont really have enough knowledge to accomplish this, this is the codes I'm trying miserably to use....

QUOTE
LastFolder: Right([Folder],InStrRev(InStrRev(InStrRev(1,[Folder],"\")+1,[Folder],"\")-1,[Folder],"\"))


Any help appreciated, Cheers
Go to the top of the page
 
ranman256
post Dec 1 2017, 11:54 AM
Post#2



Posts: 788
Joined: 25-April 14



I use this function. Paste into a module.
usage:
getDirName( "c:\folder\myfile.xls")

CODE
Private Sub getDirName(ByVal psFilePath)
Dim i As long

if not IsNull(psFilePath) then
  i = InStrRev(psFilePath, "\")      
  If i > 0 Then  getDirName= Left(psFilePath, i)
endif

End Sub
Go to the top of the page
 
theDBguy
post Dec 1 2017, 12:53 PM
Post#3


Access Wiki and Forums Moderator
Posts: 71,233
Joined: 19-June 07
From: SunnySandyEggo


Hi,

To get the last folder, you could try something like:

Mid([FilePath], InStrRev([FilePath], "\", Len([FilePath])-1))

Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    16th December 2017 - 09:12 PM