Flasher

|
Posted: Thu Mar 22, 2012 16:20 Post subject: |
|
|
Code: | '==================================================================
' Переименовать выделенные htm(l)-файлы по URL-тегу в первой строке
' Параметры: %WL
'==================================================================
With WScript.Arguments : If .Count = 0 Then WScript.Quit
List = .Item(0) : End With : Const M = 1
With CreateObject("Scripting.FileSystemObject")
For Each F in Split(.GetFile(List).OpenAsTextStream(1, -1).ReadAll, vbNewLine)
If .FileExists(F) Then
Ext = .GetExtensionName(F)
If InStr("htm|html|hta", Ext) Then
Set File = .GetFile(F)
Line = File.OpenAsTextStream(1, -2).ReadLine : NN = InStr(Line, "URL=") + 4
Name = Mid(Line, NN, InStrRev(Line, """>") - NN) : l = 0
If InStr(Name, "..") = 1 Then Name = Mid(Name, 3)
Name = .GetBaseName(Replace(Name, "/", "..")) & "." & Ext : FN = Name
Do While .FileExists(.GetParentFolderName(F) & "\" & Name)
l = l + 1
If l < 10^M Then PFix = Right(String(M, "0") & l, M) Else PFix = l
Name = .GetBaseName(FN) & " (" & PFix & ")." & .GetExtensionName(FN)
Loop : File.Name = Name
End If
End If
Next
End With |
Last edited by Flasher on Fri Mar 23, 2012 16:56; edited 3 times in total |
|