기본적으로 서로 다른 파일 이름의 유사성/근접성을 측정해야하므로이 작업은 간단한 작업이 아닙니다. 내 평범한 접근 방식은 파일 이름에서 제목을 추출하고 정규화 한 다음 가장 왼쪽 일치를 사용하여 비교하는 것입니다. 이 같은 것이 작동 할 수도 있습니다.
Set fso = CreateObject("Scripting.FileSystemObject")
Set re = New RegExp
re.Pattern = "^\d+(-\d+)?\s+"
Set rs = CreateObject("ADOR.Recordset")
rs.Fields.Append "NormalizedName", 200, 255
rs.Fields.Append "Length", 3
rs.Fields.Append "Path", 200, 255
rs.Open
' Store the full paths of the files and their associated normalized name in
' a disconnected recordset. The "Length" field is used for sorting (see below).
For Each f In fso.GetFolder("C:\some\folder").Files
normalizedName = LCase(re.Replace(fso.GetBaseName(f.Name), ""))
rs.AddNew
rs("NormalizedName").Value = normalizedName
rs("Length").Value = Len(normalizedName)
rs("Path").Value = f.Path
rs.Update
Next
' sort to ensure that the shortest normalized name always comes first
rs.Sort = "NormalizedName, Length ASC"
ref = ""
Set keeplist = CreateObject("Scripting.Dictionary")
rs.MoveFirst
Do Until rs.EOF
path = rs("Path").Value
name = rs("NormalizedName").Value
currentExtension = LCase(fso.GetExtensionName(path))
If ref <> "" And ref = Left(name, Len(ref)) Then
' same title as last file, so check if this one is a better match
If extension <> "mp3" And currentExtension = "mp3" Then
' always pick MP3 version if it exists
keeplist(ref) = path
extension = currentExtension
ElseIf extension = currentExtension _
And IsNumeric(Left(fso.GetBaseName(keeplist(ref)), 1)) _
And Not IsNumeric(Left(fso.GetBaseName(path), 1)) Then
' prefer file names not starting with a number when they have the
' same extension
keeplist(ref) = path
End If
Else
' first file or different reference name
ref = name
extension = currentExtension
keeplist.Add ref, path
End If
rs.MoveNext
Loop
rs.Close
For Each ref In keeplist
WScript.Echo keeplist(ref)
Next
위의 코드에서 다루지 않는 엣지 케이스가 있으므로 처리시주의해야합니다. 또한 코드는 단일 폴더 만 처리합니다. 폴더 트리를 처리하려면 추가 코드가 필요합니다 (예를 들어 here 참조).
죄송합니다. Ansgar보다 빨리 응답하지는 않았지만, 요청한대로 누군가 내 질문에 답하는 이메일을받지 못했습니다. 어쨌든 감사합니다. 나는 그것을 밖으로 시도하고 알려 드리겠습니다. – user2444243
와우, 그게 내가 지키고 싶어하는 사람들의 훌륭한 목록 (키플리스트)을 만들었 어. 나는 원하지 않는 것들에 대한 삭제 루틴을 스크립팅하고 알릴 것이다. – user2444243