Help me with Custom Fields
Posted: Fri Feb 03, 2006 10:05 am
Help me with Custom Fields... i want to have a field named "Date Created" or "Date Modified" Field... which you know sorts my mp3 on the date which is created... thankx
The Music Manager for Serious Collectors
http://www.mediamonkey.com/forum/
Code: Select all
[SelectedFilesStoreDate]
FileName=SelectedFilesStoreDate.vbs
ProcName=SelectedFilesStoreDate
Order=5
DisplayName=SelectedFilesStoreDate
Description=SelectedFilesStoreDate
Language=VBScript
ScriptType=0Code: Select all
'To store the DateCreated of a file to field Custom3, use:
' mySong.Custom3 = GetFileDateCreated(mySong.Path)
'To store the DateLastModified of a file to field Custom3, use:
' mySong.Custom3 = GetFileDateLastModified(mySong.Path)
'Change the line with "CHANGE HERE" according to what you want from the above possibilities
Sub SelectedFilesStoreDate
Dim mySongList : Set mySongList = SDB.CurrentSongList
If mySongList.Count = 0 Then
SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
Exit Sub
End If
Dim i, mySong
For i = 0 To mySongList.Count - 1
Set mySong = mySongList.Item(i)
mySong.Custom3 = GetFileDateCreated(mySong.Path) 'CHANGE HERE
mySong.UpdateDB
Next
End Sub
Function GetFileDateCreated(FilePath)
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim File : Set File = FSO.GetFile(FilePath)
GetFileDateCreated = File.DateCreated
End Function
Function GetFileDateLastModified(FilePath)
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim File : Set File = FSO.GetFile(FilePath)
GetFileDateLastModified = File.DateLastModified
End FunctionCode: Select all
'Modified 1/3/06 to save date in Custom3 as YYYYMMDD HH:MM format for improved sorting by date created
'To store the DateCreated of a file to field Custom3:
' mySong.Custom3 = GetFileDateCreated(mySong.Path)
'To store the DateLastModified of a file to field Custom3:
' mySong.Custom3 = GetFileDateLastModified(mySong.Path)
'Change the line with "CHANGE HERE IF YOU WANT" according to what you want (from the above possibilities)
Function pd(n, totalDigits)
if totalDigits > len(n) then
pd = String(totalDigits-len(n),"0") & n
else
pd = n
end if
End Function
Sub SelectedFilesStoreDate
Dim mySongList
Set mySongList = SDB.SelectedSongList
If mySongList.Count = 0 Then
Set mySongList = SDB.AllVisibleSongList
If mySongList.Count = 0 Then
SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
Exit Sub
End If
End If
Dim i, mySong, fd, fdt,fdtyyyymmd
For i = 0 To mySongList.Count - 1
Set mySong = mySongList.Item(i)
fdt = GetFileDatecreated(mysong.path) 'CHANGE HERE IF YOU WANT
if isdate(fdt) then
fd = cDate(fdt)
fdtyyyymmdd=Year(fd)&pd(month(fd),2)&pd(day(fd),2)&" "&formatdatetime(fd,vbShortTime)
' msgbox(fdtyyyymmdd)
mySong.Custom3 = fdtyyyymmdd
mySong.UpdateDB
end if
Next
End Sub
Function GetFileDateCreated(FilePath)
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim File
Set File = FSO.GetFile(FilePath)
GetFileDateCreated = File.DateCreated
End Function
Function GetFileDateLastModified(FilePath)
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim File
Set File = FSO.GetFile(FilePath)
GetFileDateLastModified = File.DateLastModified
End Functioneljay05 wrote:Help me with Custom Fields... i want to have a field named "Date Created" or "Date Modified" Field... which you know sorts my mp3 on the date which is created... thankx
Code: Select all
'To store the DateCreated of a file to field Custom3, use:
' mySong.Custom3 = GetFileDateCreated(mySong.Path)
'To store the DateLastModified of a file to field Custom3, use:
' mySong.Custom3 = GetFileDateLastModified(mySong.Path)
'Change the line with "CHANGE HERE" according to what you want from the above possibilities
Sub SelectedFilesStoreDate
Dim mySongList : Set mySongList = SDB.CurrentSongList
If mySongList.Count = 0 Then
SDB.MessageBox "Nothing selected!", mtError, Array(mbOK)
Exit Sub
End If
Dim i, mySong
For i = 0 To mySongList.Count - 1
Set mySong = mySongList.Item(i)
mySong.Custom3 = GetFileDateCreated(mySong.Path)
mySong.DateAdded = GetFileDateCreated(mySong.Path)
'CHANGE HERE
mySong.UpdateDB
Next
End Sub
Function GetFileDateCreated(FilePath)
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim File : Set File = FSO.GetFile(FilePath)
GetFileDateCreated = File.DateCreated
End Function
Are you aware that MM already keeps track of date added to library (the "Added" field)?Another Drunk NPC wrote:Thanks for the script! It's indispensable.![]()
I added a line of code that sets the "Date Added To Library" time to the filetime. In my opinion this makes "Recently Added" playlists 100% more useful.
Cheers.
This is just great. Thanks a lot. Is there a way to make this script run on each file upon being imported to the library?Guest wrote:Here is my attempt at modifying the script to use YYYYMMDD HH:MM format for improved sorting. I'm learning as I go, so it might be a little clumsy. It also borrows from other examples I found on the net. If the formatting disappears when I post this (as it does in my preview), I apologize. This would be saved as an alternate version of SelectedFilesStoreDate.vbs:
EDIT Peke: Just made it look better.Code: Select all
'Modified 1/3/06 to save date in Custom3 as YYYYMMDD HH:MM format for improved sorting by date created 'To store the DateCreated of a file to field Custom3: ' mySong.Custom3 = GetFileDateCreated(mySong.Path) 'To store the DateLastModified of a file to field Custom3: ' mySong.Custom3 = GetFileDateLastModified(mySong.Path) 'Change the line with "CHANGE HERE IF YOU WANT" according to what you want (from the above possibilities) Function pd(n, totalDigits) if totalDigits > len(n) then pd = String(totalDigits-len(n),"0") & n else pd = n end if End Function Sub SelectedFilesStoreDate Dim mySongList Set mySongList = SDB.SelectedSongList If mySongList.Count = 0 Then Set mySongList = SDB.AllVisibleSongList If mySongList.Count = 0 Then SDB.MessageBox "Nothing selected!", mtError, Array(mbOK) Exit Sub End If End If Dim i, mySong, fd, fdt,fdtyyyymmd For i = 0 To mySongList.Count - 1 Set mySong = mySongList.Item(i) fdt = GetFileDatecreated(mysong.path) 'CHANGE HERE IF YOU WANT if isdate(fdt) then fd = cDate(fdt) fdtyyyymmdd=Year(fd)&pd(month(fd),2)&pd(day(fd),2)&" "&formatdatetime(fd,vbShortTime) ' msgbox(fdtyyyymmdd) mySong.Custom3 = fdtyyyymmdd mySong.UpdateDB end if Next End Sub Function GetFileDateCreated(FilePath) Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") Dim File Set File = FSO.GetFile(FilePath) GetFileDateCreated = File.DateCreated End Function Function GetFileDateLastModified(FilePath) Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") Dim File Set File = FSO.GetFile(FilePath) GetFileDateLastModified = File.DateLastModified End Function
Code: Select all
'Modified 5/1/15 to save date in Custom3 as YYYYMMDD HH:MM format on track import
'To store the DateCreated of a file to field Custom3:
' mySong.Custom3 = GetFileDateCreated(mySong.Path)
'To store the DateLastModified of a file to field Custom3:
' mySong.Custom3 = GetFileDateLastModified(mySong.Path)
'Change the line with "CHANGE HERE IF YOU WANT" according to what you want (from the above possibilities)
Sub onStartup
Script.RegisterEvent SDB, "OnTrackAdded", "AddFileStoreDate"
End Sub
Function pd(n, totalDigits)
if totalDigits > len(n) then
pd = String(totalDigits-len(n),"0") & n
else
pd = n
end if
End Function
Sub AddFileStoreDate(mysong)
Dim fd, fdt, fdtyyyymmd
fdt = GetFileDatecreated(mysong.path) 'CHANGE HERE IF YOU WANT
if isdate(fdt) then
fd = cDate(fdt)
fdtyyyymmdd=Year(fd)&pd(month(fd),2)&pd(day(fd),2)&" "&formatdatetime(fd,vbShortTime)
'msgbox(fdtyyyymmdd)
mySong.Custom3 = fdtyyyymmdd
mySong.UpdateDB
end if
End Sub
Function GetFileDateCreated(FilePath)
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim File
Set File = FSO.GetFile(FilePath)
GetFileDateCreated = File.DateCreated
End Function
Function GetFileDateLastModified(FilePath)
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim File
Set File = FSO.GetFile(FilePath)
GetFileDateLastModified = File.DateLastModified
End Function