Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with MP3 rename script

369 views
Skip to first unread message

Mike Bouchard

unread,
May 31, 2002, 6:09:55 PM5/31/02
to
I am hoping that someone can help me out. I have been working on a
script that gets the id3 tag from a MP3. I have found an ASP page
that does this but am having some difficulty converting this to vbs.
The script will be posted below but here is the problem I am having.

1) When I run the script and use a command as such:
For each MP3 in Folder
msg = msg & vbcrlf & "Name" & vbtab & "File.name" & vbcrlf &
"Atrist:" & vbtab & strArtist & vbcrlf _
& "Song:" & vbtab & strSongName & etc...
Next

I only get the file name and artist nothing else.

2) When I run the script and the write these files to a txt file I
get some extra characters at the end of the file.
For example:

For each MP3 in Folder
WriteToLog("Name" & vbTab & Trim(File.Name)) & vbcrlf
WriteToLog("Artist" & vbtab & Trim(StrArtist)) & vbcrlf
WriteToLog("track" & vbTab & Trim(strSongName)) & vbcrlf
etc...
Next

I get all the information I am looking for (if it is there) but also
get some characters that look like a tiny square (Can't paste it
here).

3) Is something that I am hoping I someone can help me with.
My goal is to get a artists name, create a folder using that name,
rename the file to equal Artist - Song.mp3 For example I have a song
with the file name of 01 - Space Truckin'.mp3. What then happen is a
folder would be created called Deep Purple, the file would be moved to
the folder and renamed with the artist and song title for a result of
d:\MP3\Deep Purple\Deep Purple - Space Truckin'.mp3.

I think I can do the above but am wondering how to handle mp3's that
don't have an ID3 tag or either the Artist or Song Title are missing.
What I would like to happen here is to either leave these files alone
or create a temp file and move these files with no file name change.

I hope that I am not rambling too much and that someone will be able
to help me.

Thank you in advance for your help.

Mike

-------------------------------------------------
Script
------------------------------------------------

const adTypeBinary = 1
const adModeReadWrite = 3

dim Stream
dim strTag, strSongName, strArtist, strAlbum, strYear, _
strComment, strGenre, strFile

'Specify the folder to iterate through, displaying all the MP3s
folder = "D:\Testing\MP3\"

'Grab the folder information
Dim FSO', Folder, File
Set FSO = CreateObject("Scripting.fileSystemObject")
Set Folder = FSO.GetFolder(folder)


set stream = createobject("adodb.stream")
Stream.Type = adTypeBinary
stream.mode = adModeReadWrite

'Loop through the files in the folder
For Each File in Folder.Files

Stream.Open
Stream.LoadFromFile File.Path

'Read the last 128 bytes
Stream.Position = Stream.size - 128

'Read the ID3 v1 tag info
strTag = ConvertBin(Stream.Read(3))
if ucase(strTag) = "TAG" then
strSongName = ConvertBin(Stream.Read(30))
strArtist = ConvertBin(Stream.Read(30))
strAlbum = ConvertBin(Stream.Read(30))
strYear = ConvertBin(Stream.Read(4))
strComment = ConvertBin(Stream.Read(30))
end if

WriteToLog("Name" & vbTab & File.Name) & vbcrlf
WriteToLog("Artist" & vbtab & StrArtist) & vbcrlf
WriteToLog("track" & vbTab & strSongName) & vbcrlf
WriteToLog("Album" & vbtab & strAlbum) & vbcrlf
WriteToLog("Year" & vbtab & strYear) & vbcrlf
WriteToLog("Comment" & vbtab & strComment) & vbcrlf
WriteToLog("") & vbcrlf

'OR
'msg = msg & "Name" & vbTab & File.Name & vbcrlf & _
' & "Artist" & vbtab & StrArtist & vbcrlf _
' & "track" & vbTab & strSongName & vbcrlf _
' & "Album" & vbtab & strAlbum & vbcrlf _
' & "Year" & vbtab & strYear & vbcrlf _
' & "Comment" & vbtab & strComment & vbcrlf _
' & ("") & vbcrlf

'OR
' msgbox "Name" & vbTab & File.Name & vbcrlf & _
' & "Artist" & vbtab & StrArtist & vbcrlf _
' & "track" & vbTab & strSongName & vbcrlf _
' & "Album" & vbtab & strAlbum & vbcrlf _
' & "Year" & vbtab & strYear & vbcrlf _
' & "Comment" & vbtab & strComment & vbcrlf _
' & ("") & vbcrlf

Stream.Close

Next
Set Stream = Nothing 'Clean up...

Msgbox "DONE"

Function ConvertBin(Binary)
'This function converts a binary byte into an ASCII byte.
for i = 1 to LenB(Binary)
strChar = chr(AscB(MidB(Binary,i,1)))
ConvertBin = ConvertBin & strChar
Next
End Function

Sub WriteToLog(string)
If not Fso.FileExists("c:\MP3.Log") Then
Set fLog = Fso.CreateTextFile("c:\mp3.log", TRUE)
fLog.Close
End if
Set fLog = Fso.OpenTextFile("c:\mp3.log", 8)
fLog.WriteLine(string)
fLog.Close
End Sub

Stuart Bailie

unread,
May 31, 2002, 7:08:46 PM5/31/02
to
I'm not sure about problems 1) and 3) but 2) is just a non
printable character. Normally this is nothing to be worried about.

I tried looking at your code and I couldn't find the problem of an
unknown ASCII code being printed. I did note that your series of
WritetoLog had a '& vbcrlf' outside of each function call.
Perhaps this is your problem.

As your goal is to create it so files are sorted the same way I
have mine I can give you a little help.

The following script moves a files to a folder based on the file
name up one character shy of a '-'. This should give you a quick
boost in building this script.


'-=-=-=-= -=-=-=-= -=-=-=-= -=-=-=-=
'Script
'-=-=-=-= -=-=-=-= -=-=-=-= -=-=-=-=

DIM WshShell
DIM oFS
DIM FileName
DIM oCurrentPath
DIM ArtistDirectory

SET WshShell = WScript.CreateObject("WScript.Shell")
SET oFS = CreateObject("Scripting.FileSystemObject")
SET oCurrentPath = oFS.GetFolder(WshShell.CurrentDirectory)

FileCount = oCurrentPath.Files.Count
Counter = FileCount
FOR EACH Item IN oCurrentPath.Files
FileName = Item
IF UCase(Right(FileName, 3)) = "MP3" THEN
ArtistDirectory = Left(FileName, InStr(FileName, "-") - 2)
IF oFS.FolderExists(ArtistDirectory) = FALSE THEN
oFS.CreateFolder(ArtistDirectory)
END IF
oFS.MoveFile FileName, ArtistDirectory & "\"
END IF
' Counter = Counter - 1
NEXT


mbou...@ci.charlotte.nc.us (Mike Bouchard) wrote in
news:e6a0365a.02053...@posting.google.com:

Message has been deleted

Mark_Pryor

unread,
Jun 1, 2002, 11:12:22 AM6/1/02
to
Hi Mike,

regarding 2) (inline)
Mike Bouchard <mbou...@ci.charlotte.nc.us> wrote in message
news:e6a0365a.02053...@posting.google.com...


> I am hoping that someone can help me out. I have been working on a
> script that gets the id3 tag from a MP3. I have found an ASP page
> that does this but am having some difficulty converting this to vbs.
> The script will be posted below but here is the problem I am having.
>
> 1) When I run the script and use a command as such:
> For each MP3 in Folder
> msg = msg & vbcrlf & "Name" & vbtab & "File.name" & vbcrlf &
> "Atrist:" & vbtab & strArtist & vbcrlf _
> & "Song:" & vbtab & strSongName & etc...
> Next
>
> I only get the file name and artist nothing else.
>
> 2) When I run the script and the write these files to a txt file I
> get some extra characters at the end of the file.
> For example:
>
> For each MP3 in Folder
> WriteToLog("Name" & vbTab & Trim(File.Name)) & vbcrlf
> WriteToLog("Artist" & vbtab & Trim(StrArtist)) & vbcrlf
> WriteToLog("track" & vbTab & Trim(strSongName)) & vbcrlf
> etc...
> Next
>

You are struggling with the ID3 1.1 format, which
provides for a track number in the comment.

The Trim() method will remove trailing blanks and NULL, but
in some cases your strComment will have a track number
on the end. The value is < 32, thus you see a control character.

if ( Asc(Right( strComment, 1)) < 32 ) then
' its a track number, strip it off and use it
nTrack = Asc(Right( strComment, 1))
strComment = trim(Left(strComment, len( strCommtent) - 2 ))
end if


hth,
Mark Pryor


Mike Bouchard

unread,
Jun 1, 2002, 7:13:48 PM6/1/02
to
Stuart and Christoph,

I want to thank both of you for your replies and suggestions. Both of
you commented on the vbcrlf I had in the writeline command, it seems
that when I was testing the "msg = msg & file & vbcrlf & song & vbcrlf
...." I neglected to remove the return when I went back to writeline.
Thank you for pointing that out, it did remove most of the extra
characters I was getting.


"Christoph Basedau" <cb_no...@gmx.de> wrote in message news:<adaaad$noh$05$1...@news.t-online.com>...
--snip>

> > 1) When I run the script and use a command as such:
>

> [Displaying tags]


>
> > I only get the file name and artist nothing else.
>

> 'ConvertBinary' from your Script worked fine for me.
> So maybe the tags themselves are incomplete or
> there was a typo in your var-names.
> (better use Option Explicit)
----end snip

The tag is complete in that when I use the writeline method I get the
information I am looking for but when I do the msg = msg & file
info.... I only get the file name and artist. I am copying and
pasting so I do not believe it is a typo but I will look again.

Thank you for your time and the script attached. I will have a look
at it. are you using this or is it something you put together in
reply to my original post?

Mike Bouchard


>
> If BinaryReading with adodb-stream doesnt work as supposed,
> you could instead try active-x Components for reading
> id-Tags:
> http://home.sprintmail.com/~mpryor/wshmp3.htm
> http://www.serverscripting.com/view/1097.html
>
> > 2) [Strange Chars when writing tags to Log]
>
> Could be some non-printable in the tag.
> (I had some ascii-11 at the end of the comment-tag)
>
> On the other hand you do something like:
> fLog.Writeline string & vbCRLF
> this doesnt result in strange chars (at least in my editor)
> but you dont need a vbCRLF in WriteLine cause it automatically
> adds one (so thats why its called writeLINE).


>
> > 3) Is something that I am hoping I someone can help me with.
> > My goal is to get a artists name, create a folder using that name,
> > rename the file to equal Artist - Song.mp3 For example I have a song
> > with the file name of 01 - Space Truckin'.mp3. What then happen is a
> > folder would be created called Deep Purple, the file would be moved to
> > the folder and renamed with the artist and song title for a result of
> > d:\MP3\Deep Purple\Deep Purple - Space Truckin'.mp3.
>

> Just have to paste strArtist with strSongName and do some
> FSO-BuildPath and some FSO-CreateFolder.
> Have a look at the script below. It does the job.


>
> > I think I can do the above but am wondering how to handle mp3's that
> > don't have an ID3 tag or either the Artist or Song Title are missing.
> > What I would like to happen here is to either leave these files alone
> > or create a temp file and move these files with no file name change.
> > I hope that I am not rambling too much and that someone will be able
> > to help me.
>

> Just need to check the result you get in 'ConvertBinary'.
> If your tags (strArtist, strSongName) are empty,
> you leave the file in the first folder and edit tags mauellay.
> First have to get rid of Blanks using Trim-function.
>
> bye,
> Chris
>
> --
> Here's the script:
>
> Option Explicit
> Dim oFS, sStartFolder, oFolder, oFile, sBaseMP3
> Dim oStream
> Dim arrTags
> Dim sFileLog, oLog
> Dim nMC, nFC
>
> Const adTypeBinary = 1
> Const adModeReadWrite = 3
> Const sTAG_ENUM = "Name Artist track Album Year Comment"
>
> Set oFS = CreateObject("Scripting.fileSystemObject")
>
> sBaseMP3 = "D:\MP3"
> sStartFolder = "D:\Testing\MP3\"
> sFileLog = "c:\mp3.log"
> Set oFolder = oFS.GetFolder(sStartFolder)
>
> Call InitADODBStream ()
>
> For Each oFile in oFolder.files
> If UCase(oFS.GetExtensionNAme(oFile))="MP3" Then
> arrTags = ReadTags(oFile)
> Call MoveToFolder (oFile,arrTags(2),arrTags(1))
> Call WriteTags (arrTags)
> nFC = nFC + 1
> End if
> Next
>
> Call CleanUp()
>
> MsgBox nMC & " Files moved to " & sBaseMP3 & vbCR _
> & CStr(nFC - nMC) & " Files with incomplete " _
> & "Tag-Information Left in " & sStartFolder,0,"DONE"
>
> '+++++++++++
> Sub InitADODBStream
> set oStream = CreateObject("adodb.stream")
> oStream.Type = adTypeBinary
> oStream.mode = adModeReadWrite
> oStream.Open
> Set oLog = oFS.OpenTextFile(sFileLog, 8, true)
> nMC = 0 : nFC = 0
> End Sub
>
> Function ReadTags (ByRef oFile)
> Dim arrTags(5),strTag
> oStream.LoadFromFile oFile.Path
> oStream.Position = oStream.size - 128
> strTag = ConvertBin(oStream.Read(3))
> arrTags(0) = oFile.Name 'FileName
> If UCase(strTag) = "TAG" Then
> arrTags(1) = Trim(ConvertBin(oStream.Read(30))) 'SongName
> arrTags(2) = Trim(ConvertBin(oStream.Read(30))) 'Artist
> arrTags(3) = Trim(ConvertBin(oStream.Read(30))) 'Album
> arrTags(4) = Trim(ConvertBin(oStream.Read(4))) 'Year
> arrTags(5) = Trim(ConvertBin(oStream.Read(30))) 'Comment
> End If
> ReadTags = arrTags
> End Function
>
> Function ConvertBin(Binary)
> Dim i, strChar
> For i = 1 to LenB(Binary)
> strChar = Chr(AscB(MidB(Binary,i,1)))


> ConvertBin = ConvertBin & strChar
> Next
> End Function
>

> Sub WriteTags (arrTags)
> Dim i, arrTagNames
> arrTagNames = Split(sTAG_ENUM)
> For i=0 to UBound(arrTAgs)
> oLog.WriteLine arrTagNames(i) & vbTab & arrTags(i)
> Next
> oLog.WriteBlankLines 1
> End Sub
>
> Sub MoveToFolder (ByRef oFile, sArtist, sTitle)
> Dim sNewPath, sNewFileName, sNewFilePath
> If sArtist = empty OR sTitle = empty Then
> oLog.WriteLine "+++ Didn't Move This File: +++"
> Exit Sub
> End If
> sNewFileName = sArtist & " - " & sTitle
> sNewPath = oFS.BuildPath(sBaseMP3, sArtist)
> sNewFilePath = oFS.BuildPath(sNewPath, sNewFileName)
> Call CreateFullPath(sNewPath)
> oFile.Move sNewFilePath
> nMC = nMC + 1
> End Sub
>
> Sub CreateFullPath (ByVal f)
> Dim sParFolder, p
> Const DLM = "\"
> p = InstrRev(f,DLM)-1
> sParFolder = Left(f,p)
> If not oFs.FolderExists(sParFolder) Then _
> CreateFullPath sParFolder
> If not oFs.FolderExists(f) Then _
> oFs.CreateFolder(f)
> End Sub
>
> Sub CleanUp
> oStream.close
> oLog.close
> Set oStream = NOTHING
> Set oFS = NOTHING
> End Sub

Message has been deleted

©®1m1nÅL m1nŠeŠ

unread,
Jun 4, 2002, 5:45:22 PM6/4/02
to
Try this one. feel free to modify where needed.

Dim MyString(127)

objMP3 = InputBox("Filename", "Enter the MP3 "&_
"file to read...")
Set FSO = CreateObject("Scripting.FileSyste"&_
"mObject")
Set Mp3File = FSO.OpenTextFile(objMP3, 1, False, 0)

sBuffer = Mp3File.ReadAll

For i = 0 To 124
MyString(i) = Chr(Asc(right(sBuffer, i + 1)))
Next

For x = 0 To 124
c = 124 - x
If c > 94 and c <= 127 Then title = title & mystring(c)
If c > 64 and c <= 94 Then artist = artist & mystring(c)
If c > 34 and c <= 64 Then album = album & mystring(c)
If c > 30 and c <= 34 Then albumyear = albumyear & mystring(c)
If c > 0 and c <= 30 Then comment = comment & mystring(c)
If c = 0 then genre = mystring(c)
Next


WScript.Echo("Title: " & title)
WScript.Echo("Artist: " & artist)
WScript.Echo("Album: " & album)
WScript.Echo("Year: " & albumyear)
WScript.Echo("Comment: " & comment)
WScript.Echo("Genre: " & genre)

"Mike Bouchard" <mbou...@ci.charlotte.nc.us> wrote in message
news:e6a0365a.02053...@posting.google.com...

: I am hoping that someone can help me out. I have been working on a

:


Mike Bouchard

unread,
Jun 10, 2002, 8:34:00 PM6/10/02
to
First off I would like to apologize for not replying sooner to the
last few posts, baby decided he didn't like sleeping anymore.

It seems that lately I have been banging my head against the wall
trying to get this working properly.

I tried the ActiveX components and got it partially working, but when
I went to play the file, it came up as "embedded" in WinAmp. I then
put this to the side, would rather not use add-ins if possible.

I tried doing some more searches in MSpublic groups and came up with
more hits than before, hmm maybe I should have searched for mp3
instead of mp3 tags etc<G>. Well, I found the below script right
before someone posted it to this thread. I have been able to edit the
script and once again get it partially working for me.

As written below the script works for me but once I try to combine the
strings I start having problems.

Issues:
A)Instead of Wscript.echo(Title) and Wscript.echo(Artist) I try
wscript.echo(Title & " " & Artist) Which only pops up the Title.
B)Then I try to set a variable, i.e. strName = Title & " " &
Artist, which only gives back the Title.
C)Next I tried to write the Title and Artist to a text file, close
the file, open it for reading, do a readline set a variable, and then
readline again setting another variable. If I do a msgbox on each
variable I get the correct return but if I try to combine them I only
get the first variable

Please help me save my walls.

"??1m1n? m1n?? <guess...@anonymous.to> wrote in message news:<SxaL8.21149$jt6.7...@typhoon3.we.ipsvc.net>...

Message has been deleted

Mike Bouchard

unread,
Jun 14, 2002, 7:25:06 PM6/14/02
to
Working mp3 renamer and sorter. I still have some work to do, but
here is a working copy of the script. Please let me know what you
think and let me know if you have any ideas about the script.

The file rename has not been automated because I was coming up with
some weird names and wanted to make sure that I was not going to get
some unknown file names.

Example as taken from my log file. a bunch of U's and gibberish.
File Name 10 - Everlast - The Greatest.mp3
Artist UUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
Title 3.91UUUUUUUUUUUUUUUUUUUUUUUUUU
NewName UUUUUUUUUUUUUUUUUUUUUUUUUUUUUU -
3.91UUUUUUUUUUUUUUUUUUUUUUUUUU.mp3

OR

Original name homersintro.mp3
Artist ~ ÉšmzñYaªî>¶õØ L 6›q† ‡
Title  ÞƯ´½ ³>ý+οÓ;F(¶Ñž¶RÙ,_2s%î×
New name ~ ÉšmzñYaªî>¶õØ L 6›q† ‡ -
ÞÆ¯´½ ³>ý+οÓ;F(¶Ñž¶RÙ,_2s%î×.mp3


Thank you to everyone that has helped.

Mike

'Script Name: Rename_and_Sort_MP3.vbs
'Compiled By: Michael Bouchard
'Original script: (guessw...@anonymous.to)
'I believe this is who wrote the original script. If I am wrong
please
'let me know. mbouchar...@carolina.rr.com
'Special thanks to:
'Stuart Bailie, Christoph Basedau, Mark Pryor, and the above mentioned
'guessw...@anonymous.to. Also thanks to the posters at
'microsoft.public.scripting.wsh and vbscript who indirectly had some
input.
'
'Gets the Artist and Song from the Binary of the file. Prompts the
user
'with the
'new name, asking if the name is OK. If pops up an inputbox propmting
for
'the Artist and Song. NOTE: [ and ] is used around the file name and
'Artist and song to show if there are any unforseen characters in the
above
'variables
'Format MUST be:
' Artist - Song i.e. Deep Purple - Smoke on the water
'
'The Script requires that the input be in the format above. Once the
file name
'is set, the script looks to see if the destination folder exists, if
not
'it creates a new folder based on the artist. The script then looks
in the
'destination folder to see if a file of the same name exists, if not
it moves
'the file there renaming it to Artist - Song.mp3. If it already
exists the
'file is moved and renamed to (1)Artist - Song.mp3.
'
'
'Wish/ToDo List:
'1.When the a file already exists in the destination folder and the
(1)File
'exists also I am looking to have it advance the number so I can get
all files
'processed
'2.Add some looping to the input box section if there is a problem
with the
'name typed in.
'3.Once the script is complete I would like to see about porting it to
IE so
'I will not get so many popups. i.e. write all files to IE and use
buttons
'and checkboxes to process the renaming of the files


Option Explicit

'Const ForReading

Dim MyString(127)
Dim oFile
Dim sStartFolder
Dim strNewName
Dim sBuffer
Dim MPfile
Dim strArtist
Dim strSong
Dim dstFolder
Dim sBaseMP3
Dim Fso
Dim oFolder
Dim i
Dim x
Dim c
Dim title
Dim Artist
Dim Album
Dim albumyear
dim comment
Dim genre
Dim DoThing
Dim Flog
Dim retFname
Dim retFileName
Dim retFldr
Dim strTempName
Dim Count : Count = 0

Dim WshShell : set WshShell = WScript.CreateObject("WScript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")

sBaseMP3 = "D:\testing"


sStartFolder = "D:\Testing\MP3\"


Set oFolder = Fso.GetFolder(sStartFolder)
For each oFile in oFolder.Files
If ucase(Right(oFile.name, 4)) = ".MP3" then
Call GetMP3(oFile)
Count = Count + 1
End if
Next

Msgbox Count & " " & "Files have been processed"

Sub GetMP3(string)
Dim Seperator, Songlength
DoThing = False
Set MpFile = Fso.OpenTextFile(String, 1, False, 0)
sBuffer = MpFile.ReadAll

For i = 0 To 124
MyString(i) = Chr(Asc(right(sBuffer, i + 1)))
Next

For x = 0 To 124
c = 124 - x
If c > 94 and c <= 127 Then title = title & mystring(c)
If c > 64 and c <= 94 Then artist = artist & mystring(c)

'Commented out. If you want to use the information below then
uncomment it.
' If c > 34 and c <= 64 Then album = album & mystring(c)


' If c > 30 and c <= 34 Then albumyear = albumyear & mystring(c)
' If c > 0 and c <= 30 Then comment = comment & mystring(c)
' If c = 0 then genre = mystring(c)
Next

MPFile.close

strArtist = Replace(Artist, Chr(0), "")
strArtist = Replace(strArtist,"."," ")
strArtist = Replace(strArtist,"(","")
strArtist = Replace(strArtist,")","")
strArtist = Replace(strArtist,"[","")
strArtist = Replace(strArtist,"]","")
strArtist = Replace(strArtist,"!","")
strArtist = Replace(strArtist,"/","_")
strArtist = Replace(strArtist,"\","_")
strArtist = trim(strArtist)

strSong = Replace(title, Chr(0), "")
strSong = Replace(strSong,"[","(")
strSong = Replace(strSong,"]",")")
strSong = Replace(strSong,"/","_")
strSong = Replace(strSong,"\","_")
strSong = trim(strSong)

'START POSSIBLE LOOP
retFname = Msgbox("Original name:" & vbtab & oFile.name & vbCrLf _
& "New name:" & vbtab & "[" & strArtist & " - " & strSong &
".mp3" & "]" & vbcr _
& "Artist:" & vbTab & "[" & strArtist & "]" & vbcr _
& "Song:" & vbTab & "[" & strSong & "]" & vbCr _
& vbCr & "Is the new name correct? If not click NO and" & vbCr _
& "when prompted, type in new name.", vbYesNoCancel, "Rename
File")

If retFname = vbYes then
strNewName = strArtist & " - " & strSong & ".mp3"
ElseIf retFname = vbNo then
strTempName = InputBox("Type in the new name of the MP3. If the new
name is not known hit enter to keep original name" _
& vbcrlf & "Old file name:" & vbTab & oFile.Name)
If strTempName = "" then
retTempFname = msgbox("You have chosen" & " " & oFile.Name & " " &
"to be the name of the file. Is this correct?",vbYesNo)
If retTempFname = vbYes then
strNewName = oFile.Name
ElseIf retTempFname = vbNo then
'POSSIBLE LOOP
End if
ElseIf ucase(Right(strTempname, 4)) <> ".MP3" then
strNewName = strTempName & ".mp3"
seperator = InstrRev(strTempName,"-") 'count left to the first
occurance of "-"
if (seperator >= 1) then 'if the seperator exists split into
artist (folderName) and song (trackName)
strArtist = Trim(Left(strTempName,seperator - 1)) 'seperate
artist
songLength= (Len(strTempName)- seperator) 'work out chr length
of song
strSong = Trim(right(strTempName,songLength))
'seperate song
End if
msgbox "New name:" & vbTab & strNewName & vbCr _
& "Artist:" & vbTab & strArtist & vbcr _
& "Song:" & vbTab & strSong
End if
ElseIf retFname = vbCancel then
wscript.Quit

End if
'END POSSIBLE LOOP

WriteToLog("Original name" & vbtab & oFile.Name)
WriteToLog("Artist" & vbTab & vbtab & strArtist)
WriteToLog("Title" & vbTab & vbTab & strSong)
WriteToLog("New name" & vbTab & vbtab & strNewName)
WriteToLog("")
On Error Resume Next

If not Fso.FolderExists(sBaseMP3 & "\" & strArtist) then
dstFolder = Fso.CreateFolder(sBaseMP3 & "\" & strArtist)
Else
dstFolder = sBaseMP3 & "\" & strArtist
End if

'This error checking might not be needed.
If Err.Number > 0 then
Dothing = False
Msgbox err.number & vbtab & ofile.name
End if
On Error goto 0

If not Fso.FileExists(dstFolder & "\" & strNewName) Then
Fso.MoveFile oFile.Path, dstFolder & "\" & strNewName
Else
'DO SOME TYPE OF LOOP HERE. POSSIBLE SUB CALL TO RENAME FILE AS
NEEDED ADDING TO THE (1).
'right now this will fail if a file is already named (1)strnewname.
Fso.MoveFile oFile.Path, dstFolder & "\" & "(1)" & strNewName
End If

'Clean up
Set MpFile = Nothing
MyString(i) = ""
sBuffer = ""
Title = ""
Artist = ""
strNewName = ""
strArtist = ""
strSong = ""
'album = ""
'albumyear = ""
'comment = ""
'genre = ""
End Sub

Sub WriteToLog(string)
If not Fso.FileExists(sStartFolder & "MP3.Log") Then
Set fLog = Fso.CreateTextFile(sStartFolder & "mp3.log", TRUE)
fLog.Close
End if
Set fLog = Fso.OpenTextFile(sStartFolder & "mp3.log", 8)
fLog.WriteLine(string)
fLog.Close
End Sub

0 new messages