Der folgenden Programm komprimiert Webseiten. Für die Dateizugriffe wird die Microsoft Scripting Runtime verwendet, welche über den Menüpunkt “Projekte” >> “Verweise” hinzugefügt wird. Die Dateien werden per Drag & Drop auf die Listbox gezogen. Es werden alle doppelten Leerzeichen, Tabulatoren, Zeilenumbrüche und Kommentare aus den Dokumenten entfernt. Bitte testen Sie das Programm nicht ohne eine Sicherheitskopie Ihrer Daten anzulegen, da trotz ausgiebiger Prüfungen immer Fehler möglich sind.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | Option Explicit Private Sub Form_Load() List1.OLEDropMode = 1 End Sub Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single) Dim myFile As Variant For Each myFile In Data.Files List1.AddItem myFile Next End Sub Private Sub cmdKomprimieren_Click() Dim x As Integer Dim ff As Integer Dim myFile As String Dim myContent As String Dim myFSO As FileSystemObject Set myFSO = CreateObject("Scripting.FileSystemObject") For x = 0 To List1.ListCount - 1 myFile = List1.List(x) If myFSO.FileExists(myFile) Then 'Datei lesen ff = FreeFile Open myFile For Binary As #ff myContent = Space$(LOF(ff)) Get #ff, , myContent Close #ff 'Leerzeichen, Tabulatoren und Zeilenumbrüche entfernen myContent = Replace(myContent, vbCrLf, "") myContent = Replace(myContent, vbTab, "") While InStrRev(myContent, " ") <> 0 myContent = Replace(myContent, " ", " ") Wend 'Kommentare entfernen Dim iStart, iEnde, i As Integer iStart = 1 iEnde = 1 i = InStr(iStart, myContent, "<!--") While i <> 0 iStart = i iEnde = InStr(iStart, myContent, "-->") myContent = Replace(myContent, Mid(myContent, iStart, iEnde - iStart + 3), "") i = InStr(iStart, myContent, "<!--") Wend 'Sicherheitskopie anlegen If chkSicherheitskopie.Value = 1 Then Call myFSO.CopyFile(myFile, myFile + ".bak", True) End If 'Datei schreiben ff = FreeFile Open myFile For Output As #ff Print #ff, myContent Close #ff End If Next End Sub |
Tags: drag, drop, komprimieren