Page 1 of 1

Music & directory retrieval

Posted: Sat Aug 23, 2008 2:30 pm
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.

Re: Music & directory retrieval

Posted: Sat Aug 23, 2008 6:24 pm
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"

Re: Music & directory retrieval

Posted: Sat Aug 23, 2008 9:51 pm
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

Re: Music & directory retrieval

Posted: Mon Aug 25, 2008 12:06 am
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

Re: Music & directory retrieval

Posted: Mon Aug 25, 2008 12:37 am
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)