|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File ExtensionIs there a funciton to get a file extension. I tried using instr rev
looking for a period under file name but it was not reliable because sometimes the extension is less then three characters long and sometime a folder has periods in it PathFindExtension: File Extension from Local/Remote/IP/UNC Filename:
http://vbnet.mvps.org/index.html?code/fileapi/pathfindextension.htm -- Show quoteHide quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp Veign's Blog http://www.veign.com/blog -- <wa***@aol.com> wrote in message news:rp26129taaghol41o304ujrv78m2h1c0i4@4ax.com... > Is there a funciton to get a file extension. I tried using instr rev > looking for a period under file name but it was not reliable because > sometimes the extension is less then three characters long and > sometime a folder has periods in it > There may be something I haven't considered, but.....
It doesn't seem that there's really any need to use the shlwapi API. According to Randy's examples the PathFindExtension seems to be no more and no less accurate than just doing InstrRev to find the last "\" and then doing InstrRev from there to the end looking for "." If either returns 0, or if the second test returns length of string, then there's no extension. Otherwise it's whatever comes after "." (Interestingly, the Setup1 code uses a completely different approach, checking for the last "." with InstrRev, then checking after that point for both "\" and "/". If first check returns > 0, and checks for both "\" and "/" return 0, then extension is whatever's after "." ) Show quoteHide quote > PathFindExtension: File Extension from Local/Remote/IP/UNC Filename: > http://vbnet.mvps.org/index.html?code/fileapi/pathfindextension.htm > Some years ago I wrote a tip of the month that I call Get Folder, Name or
Extension. Link to http://www.buygold.net/tips then look for the May 1999 tip of the month. A sample program is provided. From the tip's intro: Some years ago I wrote several functions to parse a fully qualified file name into the path [folder], file name with extension, file name without extension and the file's extension. Recently I noted discussion in news groups dealing with this subject so I decided to make this the tip-of-the-month. 2002/10/15 I converted the function for VB.Net. And I added a function called 'AppPath' which returns the executing path - the function is the same as VB6's App.Path function. 2003/02/03 Function AddBackslash is moved to a separate module for the VB6 version. Add a browse button. 2005/10/21 I moved the code to a class module called 'cFilenameParse'. The module 'modPath.bas' is still distributed but all the functionality is now contained in 'cFilenameParse.cls'. And the word 'path' is replaced with 'folder' in most references. Cheers, Larry Rebich More tips link to: http://www.buygold.net/tips Please: No personal e-mail questions :-) <wa***@aol.com> wrote in message Show quoteHide quote news:rp26129taaghol41o304ujrv78m2h1c0i4@4ax.com... > Is there a funciton to get a file extension. I tried using instr rev > looking for a period under file name but it was not reliable because > sometimes the extension is less then three characters long and > sometime a folder has periods in it > On Sat, 11 Mar 2006 12:39:12 -0500, wa***@aol.com wrote:
>Is there a funciton to get a file extension. I tried using instr rev ' ############################################################>looking for a period under file name but it was not reliable because >sometimes the extension is less then three characters long and >sometime a folder has periods in it ' ' Test.DAT returns "DAT" ' Function ExtractFileExtension$(Fle$) Dim L9% For L9 = Len(Fle$) To 1 Step -1 ' --- Rightmost "." If Mid$(Fle$, L9, 1) = "." Then ExtractFileExtension$ = Mid$(Fle$, L9 + 1) Exit For End If ' --- We are into the Path If InStr(":\", Mid$(Fle$, L9, 1)) Then Exit For End If Next End Function
Why ?? (Path/File access error (Error 75)
VB.NET or C++.NET or C# Using the replace command, please help NTFS File Access in VB6 Sub or Function is not defined Control similar to MS Access List Box write to disk and permissions How to open a chm file nicely ? Testing for "Access Denied" without trying to change the file Cross-posting - How To? |
|||||||||||||||||||||||