megaloman
22-10-2020, 22:37
MyDir = "Z:\Box_In"
MyMask = "^.*\..*$"
Set Reg = CreateObject("VBScript.RegExp")
Reg.IgnoreCase = True
Reg.Pattern = MyMask
With CreateObject("Scripting.FileSystemObject")
Set Files = .GetFolder(MyDir).Files
For Each File In Files
Filename = File.Path
If Reg.Test(Filename) Then
Set fIn = .OpenTextFile(Filename, 1, False)
On Error Resume Next
Err.Number = 0
InTxt = fIn.ReadAll
If Err.Number = 0 Then
fIn.Close
InTxt = Replace(InTxt, " ", "")
Mas = Split(InTxt, vbCrLf)
iMax = -1
For i = UBound(Mas) To LBound(Mas) Step -1
If Len(Mas(i)) <> 0 Then
iMax = i
Exit For
End If
Next
Set fIn = .CreateTextFile(Filename, True)
fIn.Close
Set fIn = .OpenTextFile(Filename, 8, False)
If iMax >= 0 Then
For i = LBound(Mas) To iMax
If Len(Mas(i)) <> 0 Then
If i <> iMax Then
fIn.WriteLine Mas(i)
Else
fIn.Write Mas(i)
End If
End If
Next
End If
fIn.Close
Else
fIn.Close
End If
On Error GoTo 0
End If
Next
End With
MsgBox "Done"
MyMask = "^.*\..*$"
Set Reg = CreateObject("VBScript.RegExp")
Reg.IgnoreCase = True
Reg.Pattern = MyMask
With CreateObject("Scripting.FileSystemObject")
Set Files = .GetFolder(MyDir).Files
For Each File In Files
Filename = File.Path
If Reg.Test(Filename) Then
Set fIn = .OpenTextFile(Filename, 1, False)
On Error Resume Next
Err.Number = 0
InTxt = fIn.ReadAll
If Err.Number = 0 Then
fIn.Close
InTxt = Replace(InTxt, " ", "")
Mas = Split(InTxt, vbCrLf)
iMax = -1
For i = UBound(Mas) To LBound(Mas) Step -1
If Len(Mas(i)) <> 0 Then
iMax = i
Exit For
End If
Next
Set fIn = .CreateTextFile(Filename, True)
fIn.Close
Set fIn = .OpenTextFile(Filename, 8, False)
If iMax >= 0 Then
For i = LBound(Mas) To iMax
If Len(Mas(i)) <> 0 Then
If i <> iMax Then
fIn.WriteLine Mas(i)
Else
fIn.Write Mas(i)
End If
End If
Next
End If
fIn.Close
Else
fIn.Close
End If
On Error GoTo 0
End If
Next
End With
MsgBox "Done"