Hello Scripting Geniuses,
I have a easy problem for you.
I have a field that displays my song ex C:\MUSIC\ALBUMS\03 - Frankie Paul Worries In The Dance.mp3
I need a script that will display "03 - Frankie Paul Worries In The Dance.mp3" for the song
and
"ALBUMS" for the directory.
I have been moving around split, right, replace functions in vbscript.
I really need to know how make the split function retrieve from the right instead of the left.
I use the "\" as the delimiter but when I go into different directories it messes up my results.
Thanks a lot for the help in advance.
Music & directory retrieval
Re: Music & directory retrieval
My solution:
Code: Select all
Dim strMusic
Dim tmpArray
strMusic = "C:\MUSIC\ALBUMS\03 - Frankie Paul Worries In The Dance.mp3"
tmpArray = Split (strMusic, "\")
' Elements in the array:
tmpArray(0) ' C:
tmpArray(1) ' MUSIC
tmpArray(2) ' ALBUMS
tmpArray(3) ' 03 - Frankie Paul Worries In The Dance.mp3"
Laszlo Menesi
Re: Music & directory retrieval
Try using InStrRev to pull from the right side of the string.
InStrRev will return 0 if the string you are searching for is not present. You could use this with an If/Then function to look for ALBUM, ARTIST, ALBUMARTIST for any string that populates your variable and parse it to return only the data you need.
Osler
Code: Select all
Dim MyString
Dim FolderPosition
Dim TrackDataArray
MyString = "C:\MUSIC\ALBUMS\03 - Frankie Paul Worries In The Dance.mp3"
FolderPosition = InStrRev(MyString, "ALBUMS") - 1
MyString = Right(MyString, (Len(MyString) - FolderPosition))
TrackDataArray = Split(MyString, "\")
MsgBox TrackDataArray(0)
MsgBox TrackDataArray(1)
Osler
Re: Music & directory retrieval
I appreciate the help, guys. Osler you kind of have the idea I was looking for. But here is the "Kicker" when I go to a directory such as C:\MUSIC\R&B\BlackEyed Peas\Black Eyed Peas - Lets Get Retarded.mp3 the message box will not display because it is looking for "ALBUM".
In short all I want to do is retrieve the last two "\" from the right. No matter how many "\" there are (Greater than 2, of course).
I hope that makes sense.
(0) will msgbox - Black Eyed Peas - Lets Get Retarded.mp3
(1) will msgbox - BlackEyed Peas
In short all I want to do is retrieve the last two "\" from the right. No matter how many "\" there are (Greater than 2, of course).
I hope that makes sense.
(0) will msgbox - Black Eyed Peas - Lets Get Retarded.mp3
(1) will msgbox - BlackEyed Peas
-
- Advanced Member
- Posts: 206
- Joined: Tue Oct 07, 2003 10:01 am
- Location: Columbus, OH
- Contact:
Re: Music & directory retrieval
Split the text as you showed previously based on the "\" Then use the Ubound function to get the number of elements in the array
Dim strMusic
Dim tmpArray
Dim numelements as Integer
strMusic = "C:\MUSIC\ALBUMS\03 - Frankie Paul Worries In The Dance.mp3"
tmpArray = Split (strMusic, "\")
numelements = Ubound(tmpArray)
Now you can retrieve the (song.mp3) since it is the last element used
song = tmpArray(numelements)
album = tmpArray(numelements - 1)
Dim strMusic
Dim tmpArray
Dim numelements as Integer
strMusic = "C:\MUSIC\ALBUMS\03 - Frankie Paul Worries In The Dance.mp3"
tmpArray = Split (strMusic, "\")
numelements = Ubound(tmpArray)
Now you can retrieve the (song.mp3) since it is the last element used
song = tmpArray(numelements)
album = tmpArray(numelements - 1)