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    
post Nov 14 2017, 08:50 AM

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....

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

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

Posts: 867
Joined: 25-April 14

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

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)

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

Access Wiki and Forums Moderator
Posts: 72,769
Joined: 19-June 07
From: SunnySandyEggo


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
Access Website | Access Blog | Email
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    21st July 2018 - 08:33 AM