by Ostrich Egg » Fri May 01, 2015 7:54 pm
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:
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
EDIT Peke: Just made it look better.
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?
EDIT: Ok, I had never done MM scripting before, but I was able to get it working
The script below adds the file created date as Custom3 on track import.
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
[quote="Guest"]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:
[code]'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]
EDIT Peke: Just made it look better.[/quote]
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?
EDIT: Ok, I had never done MM scripting before, but I was able to get it working :D
The script below adds the file created date as Custom3 on track import.
[code]'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[/code]