Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB
Expertise: Beginner
Aug 12, 2004

Easily Retrieve File Attributes

Sometimes, filenames may contain characters like "." and file-extensions may not necessarily be always 3 characters long. This code provides a handy way to get file attributes in a foolproof way.

Function GetFileExtension (FileName As String) As String
 'Filename can be with or without the absolute path.
 Dim sTemp() As String
 sTemp = Split(FileName, ".")
 GetFileExtension = sTemp(UBound(sTemp))
End Function

Function GetFileName (FileName as String, _
         Optional WithExtension As Boolean = True) As String
 'Filename can be with or without the absolute path.
 Dim sTemp() As String
 sTemp = Split(FileName, "\")
 GetFileName = sTemp(UBound(sTemp))        'FileName with Extension
 If Not WithExtension Then
    sTemp = Split(GetFileName, ".")
    Redim Preserve sTemp(UBound(Stemp-1))  'FileName without extension
    GetFileName = Join(sTemp, ".")
 End If
End Function

Function GetFilePath (FileName as String) As String
 Dim sTemp() As String
 sTemp = Split(FileName, "\")
 Redim Preserve sTemp(UBound(Stemp-1)) 
 GetFilePath = Join(sTemp, "\")
End Function
Dambar Tiwari
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap