Music & directory retrieval

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
James D
Senior Member
Posts: 133
Joined: Wed Jun 06, 2007 3:30 pm
Location: Baja California

Music & directory retrieval

Post by James D »

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.
menesi
Member
Posts: 51
Joined: Fri Jan 05, 2007 4:48 pm
Location: Debrecen, Hungary, EU

Re: Music & directory retrieval

Post by menesi »

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
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Music & directory retrieval

Post by Osler »

Try using InStrRev to pull from the right side of the string.

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) 
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
James D
Senior Member
Posts: 133
Joined: Wed Jun 06, 2007 3:30 pm
Location: Baja California

Re: Music & directory retrieval

Post by James D »

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
Circe640
Advanced Member
Posts: 206
Joined: Tue Oct 07, 2003 10:01 am
Location: Columbus, OH
Contact:

Re: Music & directory retrieval

Post by Circe640 »

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)
Post Reply