• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Show only part of a filename in a label vb6

How do i get the last part of  a filename after the last backslash and leave off the extension
Typical file name:
C:\Documents and Settings\All Users.WINDOWS\Documents\Real20CardKeno\KingKeno\SavedKingKenoGames\10 spot top row bet 10 cents.cle
Example: What i need
lblFilename = "10 spot top row bet 10 cents"
this part could be any length
0
isnoend2001
Asked:
isnoend2001
3 Solutions
 
Rgonzo1971Commented:
HI,

pls try
strFileName = "C:\Documents and Settings\All Users.WINDOWS\Documents\Real20CardKeno\KingKeno\SavedKingKenoGames\10 spot top row bet 10 cents.cle"
arrFilename = Split(strFileName, "\")
lblName = Split(arrFilename(UBound(arrFilename)), ".")(0)

Open in new window

Regards
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if you had used the FileSystemObject, you can use the basename method of the file object:
http://msdn.microsoft.com/en-us/library/aa265288%28v=vs.60%29.aspx

apart from that, the above method shall work
0
 
aikimarkCommented:
I agree with a3 about the FSO being the preferred method of getting the data you want.

If you want to hone your VB skills, you can play with different parsing methods.
* (already shown) SPLIT()
* InstrRev(), Mid(), Left()
* using a vbscript.regexp object -- the pattern I used is ".*\\(.*)\..*?"
* looping (For...Next or Do...Loop) structures
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
isnoend2001Author Commented:
Thanks
Got this from another forum:
Public Function GetBaseName(ByRef Path As String) As String
    Dim StartPos As Long, EndPos As Long
    StartPos = InStrRev(Path, "\") + 1&
    EndPos = InStrRev(Path, ".")
    GetBaseName = Mid$(Path, StartPos, EndPos - StartPos)
End Function
it seems to work fine
hate using the fso as a dependency needs adding to setups
0
 
aikimarkCommented:
hate using the fso as a dependency needs adding to setups
No.  You can instantiate this dynamically without having to worry about dependencies.  FSO is on all currently supported Windows versions.
Example:
Dim oFS As Object
Set oFS = CreateObject("scripting.filesystemobject")

Open in new window

0
 
isnoend2001Author Commented:
Thanks
Few yrs ago i had problem with fso dependencies. No longer a problem, but i can do without
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now