| Name: File_Extension (Small code to return the extension of a file from the full path) Description:These five lines of code a redesigned to show you that returning an extension of a file name is very easy. I've seen some other code to do this and don't know why the programmer made the code so large. Inputs:Full_File_Name: The file name or full file path. Returns:The extension of the file. Unknown" if it can't find the file's extension. ' ' Assumes:Make a module and copy and paste this into it. Then, make a Button. Double click on the button. When the code window pops up, put in the following: File_Extension("C:\Your\File \Here.doc") Public Function File_Extension(Full_File_Name As String) As String 'File's extension can't be longer than 5 ' characters long. If InStr(StrReverse(Full_File_Name), ".") >= 7 Or InStr(StrReverse(Full_File_Name), ".") <= 1 Then 'If it can't find the extension, it retu ' rns "Unknown". File_Extension = "Unknown" Else 'Returns the file's extension. File_Extension = Mid(Full_File_Name, Len(Full_File_Name) - InStr(StrReverse(Full_File_Name), ".") + 2) End If End Function |
File, Extension |
Express News India | Freelance ecommerce web development India