This isn't related to Access but I like to share code when I come up with it. Feel free to use this.
I have been downloading music from the internet but the albums come packed with the artist name and track number built into the filename. This annoys me and manually renaming files gets old quick. This script takes the title from the metadata and renames the file accordingly while maintaining the original file extension.
[Begin Script]
Set fso = CreateObject("Scripting.FileSystemObject")
set oFldr = fso.getfolder(inputbox("Enter complete folder path"))
Dim strString(127)
Dim strTitle
Dim strExt
Dim strNewTitle
for each ofile in oFldr.Files
strTitle = ""
filename = ofile.name
'msgbox "FileName: " & filename
Set MpFile = fs
penTextFile(ofldr & "\" & filename, 1, False, 0)
sBuffer = MpFile.ReadAll
For i = 0 To 124
strString(i) = Chr(Asc(right(sBuffer, i + 1)))
Next
For x = 0 To 124
c = 124 - x
If c > 94 and c <= 127 Then
strTitle = strTitle & strString(c)
End If
Next
MpFile.Close
strExt = lcase(fso.GetExtensionName(ofile.Name))
strNewTitle = strTitle
ofile.Name = strNewTitle
ofile.name = ofile.name & "." & strExt
Next
[End Script]
I have been downloading music from the internet but the albums come packed with the artist name and track number built into the filename. This annoys me and manually renaming files gets old quick. This script takes the title from the metadata and renames the file accordingly while maintaining the original file extension.
[Begin Script]
Set fso = CreateObject("Scripting.FileSystemObject")
set oFldr = fso.getfolder(inputbox("Enter complete folder path"))
Dim strString(127)
Dim strTitle
Dim strExt
Dim strNewTitle
for each ofile in oFldr.Files
strTitle = ""
filename = ofile.name
'msgbox "FileName: " & filename
Set MpFile = fs

sBuffer = MpFile.ReadAll
For i = 0 To 124
strString(i) = Chr(Asc(right(sBuffer, i + 1)))
Next
For x = 0 To 124
c = 124 - x
If c > 94 and c <= 127 Then
strTitle = strTitle & strString(c)
End If
Next
MpFile.Close
strExt = lcase(fso.GetExtensionName(ofile.Name))
strNewTitle = strTitle
ofile.Name = strNewTitle
ofile.name = ofile.name & "." & strExt
Next
[End Script]