Max Wanadoo
max.wanadoo at gmail.com
Sun Jan 17 09:38:12 CST 2010
To get filename: str = "c:\dir\subdir2\myfile.txt\" str = Mid(str, InStrRev(str, "\") + 1) will return "" (blank) because there is no filename there. To get foldername: str = "c:\dir\subdir2\myfile.txt\" If Right(str, 1) = "\" Then str = Left(str, Len(str) - 1) End If str = Left(str, InStrRev(str, "\") - 1) str = Mid(str, InStrRev(str, "\") + 1) Debug.Print str Max -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 17 January 2010 13:02 To: Access Developers discussion and problem solving Subject: Re: [AccessD] Simple String Help Will that work if there is a trailing backslash? John W. Colby www.ColbyConsulting.com Max Wanadoo wrote: > Or, as I posted 2 weeks ago, use the instrrev function - one line and no > code required. > > str = Mid(str, InStrRev(str, "\") + 1) > > > Max > > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Robert > Sent: 17 January 2010 01:42 > To: 'Access Developers discussion and problem solving' > Subject: Re: [AccessD] Simple String Help > > Absolutely beautiful Jurgen > > > Thank You VERY much... > > WBR > Robert > > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jurgen Welz > Sent: Saturday, January 16, 2010 8:18 PM > To: accessd at databaseadvisors.com > Subject: Re: [AccessD] Simple String Help > > > You should test that a string has been passed and make sure there is a > backslash somewhere in the path and add any other error handling you need. > > > > Function fnLastPath(strPathIn As String) As String > Dim lngLen As Long > Dim lngPos As Long > Dim strReturn As String > > lngLen = Len(strPathIn) > lngPos = InStrRev(strPathIn, "\") > If lngPos = lngLen Then > strPathIn = Left$(strPathIn, lngLen - 1) > lngPos = InStrRev(strPathIn, "\") > strReturn = Mid$(strPathIn, lngPos + 1) > Else > strReturn = Mid$(strPathIn, lngPos + 1) > End If > fnLastPath = strReturn > End Function > > Ciao Jürgen Welz Edmonton, Alberta jwelz at hotmail.com > > > >> From: robert at servicexp.com >> To: accessd at databaseadvisors.com >> Date: Sat, 16 Jan 2010 19:06:22 -0500 >> Subject: [AccessD] Simple String Help >> >> I know this should be easy, but for some reason today I just can't come up >> with a working solution.. >> >> >> The Goal: To evaluate a string (path) and return only the end (last folder >> name). >> >> This string could end differently with or without "\" >> >> Example: "\\adfs\ad_folder\sxpdata\Word Docs\" OR >> "\\adfs\ad_folder\sxpdata\Word Docs OR C:\ad_folder\sxpdata\Word Doc\ >> >> Need to return only the "Word Docs" portion >> >> I'm drawing a blank here.... >> >> >> WBR >> Robert > > _________________________________________________________________ > -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com