Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stip out part of filename

Status
Not open for further replies.

craigey

Technical User
Apr 18, 2002
510
GB
Hi guys,

I've been working on a script for organising the office MP3 collection. So far so good. All mp3's from each artist have there own folder. The only problem is that if i have 2 tracks with a variation on the artist name, such as:

"Eminem - sometrack.mp3"
"Eminem feat Dr Dre - Sometrack.mp3"
This results in 2 folders being created one called "Eminem" the other called "Eminem feat dr dre".

I know I could just remove feat, but I don't know how to delete the words inbetween "feat" & "-"

Is it possible to strip the "feat (other artists names)" out of the track name, so that all tracks by the same artist can go in the same folder?

Cheers
 
yes you can certainly do that via script, but if it is only 2 files then it seems silly to not do that manually.

Without you posting your code on how you are organizing your files it is difficult to give you a solution that will mesh well. But for this example you have given:

Code:
file2="Eminem feat Dr Dre - Sometrack.mp3"

'Split the file on the "-" character first.
fileArray = Split(file2,"-")
'Grab the artist name
Artist = fileArray(0)
'now split the artist name on the spaces
ShortArtist = Split(Artist," ")
'Grab just the name from before the first space
ShortName = ShortArtist(0)
'Create our new file name
newFileName = ShortName & " -" & fileArray(1)

Wscript.Echo newFilename

I hope you find this post helpful.

Regards,

Mark
 
Great Thanks.

It would be pointless for just one or 2 tracks, but there are literally hundreads of folders for thousands of tracks that I need to rename!

Just before you posted I managed to look into the instrev & came up with this:

Code:
str1="Eminem feat dr dre - without me.mp3"
result = InStrRev(str1, "feat")
result2 = InStrRev(str1, "-")
remove=mid(str1,result, result2 - result)
str2=replace(str1, remove,"")
msgbox(str2)

I've tested both scripts & they both seem to work fine. Is there any reason why one would be better then the other? I've heard array's can be quite slow...


 
Well I have a program for renaming files automatically, but although it has a replace function, it can't replace between "feat" & "-". Hence why I needed to do it this way. The only issue I now have is spaces in the artist names that shouldn't be there. Eg:

"Coldplay - X & Y" (correct)
"Cold play - X & Y" (incorrect)

 
I think the 2nd solution will be more robust as it doesnt care how many words the artist name contains.

Naming convention is going to be what determines which will be the better solution. If there are hundreds of files with variations, then a file named:

Eminem with dr dre - without me.mp3

Would require a seperate check such as result = InStrRev(str1, "with") In which case my solution would be better.

Where you will run into trouble is the you have files with names like this"

"The Beetles - here comes the sun.mp3"
"The Monkeys - girl.mp3"

As Tony has said, you will also encounter problems if the name has more than one hyphen. You might get past this by using the Array UBOUND instead of the second element.

I hope you find this post helpful.

Regards,

Mark
 
The only issue I now have is spaces in the artist names that shouldn't be there. Eg:

"Coldplay - X & Y" (correct)
"Cold play - X & Y" (incorrect)

I would generate a list of names to check for (variations) and enumerate through each file and use Instr to check for the variations. If they are there do the rename as needed.

I hope you find this post helpful.

Regards,

Mark
 
Thanks for pointing that out.

I've stripped the from the beginning of each artist anyway, so "the beatles" isn't an issue.

But with your version a file called:
"Kaiser Chiefs feat someone - trackname.mp3"
becomes
"Kaiser - trackname.mp3"

Is there another way round that? Oh & what is Ubound?
 
do you mean have something like a txt file & have things like:

Coldplay = cold play, codplay, codlpay
madonna = madona, madoan, maddonna, madonan

can you expand on how to impplement this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top