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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
Thanks for your registration, follow us on our social networks to keep up-to-date