Код:
![Выделить весь код](images/misc/selectcode.png)
Option Explicit
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim strSourceFolder
Dim objFile
Dim i
If WScript.Arguments.Count = 1 Then
strSourceFolder = WScript.Arguments.Item(0)
With WScript.CreateObject("Scripting.FileSystemObject")
If .FolderExists(strSourceFolder) Then
For Each objFile In .GetFolder(strSourceFolder).Files
Select Case LCase(.GetExtensionName(objFile.Name))
Case "jpg", "jpeg", "jpe"
With WScript.CreateObject("ADODB.Stream")
.Type = adTypeBinary
.Open
.LoadFromFile objFile.Path
.Position = objFile.Size - 2
If AscB(MidB(.Read(1), 1, 1)) = &HFF And AscB(MidB(.Read(1), 1, 1)) = &HD9 Then
' Nothing to do
Else
For i = .Size - 3 To 0 Step -1
.Position = i
If AscB(MidB(.Read(1), 1, 1)) = &HFF And AscB(MidB(.Read(1), 1, 1)) = &HD9 Then
.SetEOS
.SaveToFile objFile.Path, adSaveCreateOverWrite
Exit For
End If
Next
End If
.Close
End With
Case Else
' Nothing to do
End Select
Next
Else
WScript.Echo "Can't find source folder [" & strSourceFolder & "]."
WScript.Quit 2
End If
End With
Else
WScript.Echo "Usage: " & WScript.ScriptName & " <Source folder>"
WScript.Quit 1
End If
WScript.Quit 0