Accueil > > > UN EXEMPLE DE COMPRESSEUR DE FICHIERS
UN EXEMPLE DE COMPRESSEUR DE FICHIERS
Information sur la source
Description
Ce programme permet de compresser un ou plusieurs fichiers(texte, binaire...) Il utilise un ecran avec -une zone de texte contenant le nom du fichier resultat -une liste permettant de faire la selection des fichiers -un bouton lancant la compression. NOTE : Ce programme peut etre largement amélioré au niveau de la compression. C'est un exemple comme base de travail!
Source
- Public chemin
- Public disque
- ' PROGRAMME DE COMPRESSION DE DONNEES
- ' VIENT GERARD (FRANCE)
- ' Prévu pour le disque C:
- ' CECI EST UN EXEMPLE MAIS IL FAUDRAIT AMELIORER LA COMPRESSION
- ' ET LA RAPIDITE DU PROGRAMME ....
- ' En decompression on met le resultat dans c:\temp
- '
- ' prévoir un écran avec deux zones de texte
- ' une zone de saisie pour le nom du fichier compressé
- ' une zone liste (dir1) contenant les repertoires
- ' une zone liste (file1) contenant les fichiers du repertoire
- ' deux boutons radios pour chosir le disque (c ou d)
- ' deux boutons commandes pour compresser ou decompresser
- '
-
- Private Sub CommandButton1_Click()
- '
- If Len(Dir(text1.Text)) <> 0 Then
- Kill text1.Text
- End If
- Dim table(5000) As String, table2(5000) As Long, table3(255) As Long, table4(10) As String, table5(10) As Long, car As String, totalfichier As String, remplacement As String, cart As String, carr As String, resultat As String, ligne As String, ligne2 As String
- Position = 1
- tailletot = 0
- For i = 0 To file1.ListCount - 1
- If file1.Selected(i) Then
- poslong = Position + 32
- Open chemin + file1.List(i) For Binary As 1
- taille = LOF(1)
- tailletot = tailletot + taille
- totalfichier = String(taille, " ")
- Get #1, 1, totalfichier
- Close 1
- Label2.Caption = "TRAITEMENT CHOIX " + file1.List(i) + " TAILLE EN OCTETS : " + Str(taille)
- blanc = String(128, " ")
- '
- ' on écrit le nombre de caractère disponibles pour la répétition
- '
- g = 1
- temp3 = ""
- Erase table, table2, table3, table4, table5
- pos = 1
- maxix = 0
- taille2 = taille + 1
- While pos > 0
- temp = Str(Int(g / taille * 100))
- If temp <> temp3 Then
- Label2.Caption = "TRAITEMENT LECTURE " + file1.List(i) + temp + "%"
- UserForm1.Repaint
- temp3 = temp
- End If
- fin = True
- mot = ""
- While fin
- car = Mid(totalfichier, pos, 1)
- pos = pos + 1
- mot = mot + car
- tp = Asc(car + " ")
- table3(tp) = table3(tp) + 1
- If Len(mot) = 4 Or car = "" Then fin = False
- Wend
- If pos > Len(totalfichier) Then pos = 0
- If pos > 0 Then
- If Len(mot) >= 2 Then
- trouve = False
- For h = 0 To maxix
- If mot = table(h) Then
- table2(h) = table2(h) + 1
- h = maxix
- trouve = True
- End If
- Next h
- If trouve = False And maxix < 250 Then
- maxix = maxix + 1
- table(maxix) = mot
- table2(maxix) = 1
- End If
- End If
- g = pos
- End If
- Wend
- '
- ' on tri determine les caracteres
- ' à répéter
- '
- tri = True
- While tri
- tri = False
- For g = 0 To maxix
- For h = g + 1 To maxix
- If table2(g) * Len(table(g)) < table2(h) * Len(table(h)) Then
- tt1 = table(g)
- tt2 = table2(g)
- table(g) = table(h)
- table2(g) = table2(h)
- table(h) = tt1
- table2(h) = tt2
- tri = True
- End If
- Next h
- Next g
- Wend
- '
- ' tri des caracteres du moins vers le plus
- ' pour utiliser les caracteres de repetitions qui apparaissent
- ' le moins dans le fichier
- '
- For g = 0 To 10
- table5(g) = 999999999#
- Next g
- For g = 0 To 255
- For h = 0 To 10
- If table5(h) > table3(g) Then
- table5(h) = table3(g)
- table4(h) = Chr(g)
- h = 10
- End If
- Next h
- Next g
- Open text1.Text For Binary As 2
- '
- ' on prepare les 4 octets de la longueur du fichier
- '
- ligne = MKL(0)
- Put #2, Position, ligne
- Position2 = Position
- Position = Position + 4
- '
- ' on ecrit le caractère de remplacement
- '
- ligne = table4(0)
- Put #2, Position, ligne
- Position = Position + 1
- '
- ' on ecrit la longueur du nom de fichie reel
- '
- ligne = Chr(Len(Trim(file1.List(i))))
- Put #2, Position, ligne
- Position = Position + 1
- '
- ' on ecrit le nom du fichier reel
- '
- ligne = Trim(file1.List(i))
- Put #2, Position, ligne
- Position = Position + Len(ligne)
- '
- ' on ecrit les occurences des chaines
- ' 1 caractere de repetition
- ' 1 caractere pour la longueur de la zone repete
- ' la zone repete
- '
- For g = 0 To 9
- mot = table(g)
- ligne = table4(g + 1)
- Put #2, Position, ligne
- Position = Position + 1
- ligne = Chr(Len(mot))
- Put #2, Position, ligne
- Position = Position + 1
- ligne = mot
- Put #2, Position, ligne
- Position = Position + Len(ligne)
- Next g
- g = 1
- carr = table4(0)
- Position3 = Position
- While g <= Len(totalfichier)
- cart = Mid(totalfichier, g, 1)
- temp = Str(Int(g / taille2 * 100))
- If temp <> temp3 Then
- Label2.Caption = "TRAITEMENT ECRITURE " + file1.List(i) + temp + "%"
- UserForm1.Repaint
- temp3 = temp
- End If
- For h = 0 To 9
- mot = table4(h + 1)
- If cart = mot Then
- ligne = carr + mot
- Put #2, Position, ligne
- Position = Position + 2
- g = g + 1
- h = 99
- Else
- mot = table(h)
- If mot <> "" Then
- If Mid(totalfichier, g, Len(mot)) = mot Then
- ligne = table4(h + 1)
- Put #2, Position, ligne
- Position = Position + 1
- g = g + Len(mot)
- h = 99
- End If
- End If
- End If
- Next h
- If cart = carr Then
- ligne = carr + cart
- Put #2, Position, ligne
- Position = Position + 2
- g = g + 1
- Else
- If h < 99 Then
- ligne = cart
- Put #2, Position, ligne
- Position = Position + 1
- g = g + 1
- End If
- End If
- Wend
- ligne = MKL(Position - Position3)
- Put #2, Position2, ligne
- taillecomp = LOF(2)
- Close #2
- '
- ' on ecrit les caracteres de répétition
- '
- If taille > 0 Then Label2.Caption = file1.List(i) + "(" + Str(Int((Position - Position2) / Len(totalfichier) * 100)) + "%)"
- End If
- Next i
- MsgBox "OK TRAITEMENT TERMINE TAILE AVANT EN OCTETS" + Str(tailletot) + " TAILLE APRES " + Str(taillecomp) + "(" + Str(Int((taillecomp / tailletot) * 100)) + "%)"
-
- End Sub
-
- Private Sub CommandButton2_Click()
- Dim zone As String
- Dim tabler(10) As String, tablel(10) As Long, tablem(10) As String
- Open text1.Text For Binary As 1
- Position = 1
- While Position <= LOF(1)
- zone = "xxxx"
- Get #1, Position, zone
- Position = Position + Len(zone)
- longueurc = CVL(zone)
- zone = "x"
- Get #1, Position, zone
- Position = Position + Len(zone)
- carr = zone
- Get #1, Position, zone
- Position = Position + Len(zone)
- lnom = Asc(zone)
- zone = String(lnom, " ")
- Get #1, Position, zone
- Position = Position + Len(zone)
- nomfic = zone
- For g = 1 To 10
- zone = "x"
- Get #1, Position, zone
- Position = Position + Len(zone)
- tabler(g) = zone
- Get #1, Position, zone
- Position = Position + Len(zone)
- tablel(g) = Asc(zone)
- zone = String(tablel(g), "x")
- Get #1, Position, zone
- Position = Position + Len(zone)
- tablem(g) = zone
- Next g
- '
- ' on remet le fichier dans temp
- '
- Label2.Caption = "TRAITEMENT DU FICHIER " + nomfic + Str(longueurc)
- UserForm1.Repaint
- Position2 = 1
- Open "c:\temp\" + nomfic For Binary As 2
- zone = "x"
- taille2 = longueurc + 1
- For g = 1 To longueurc
- Get #1, Position, zone
- Position = Position + Len(zone)
- temp = Str(Int(Position / taille2 * 100))
- If temp <> temp3 Then
- Label2.Caption = "TRAITEMENT DU FICHIER " + nomfic + temp + "%"
- UserForm1.Repaint
- temp3 = temp
- End If
- If zone = carr Then
- Get #1, Position, zone
- Position = Position + Len(zone)
- Put #2, Position2, zone
- Position2 = Position2 + Len(zone)
- Else
- trouve = False
- For h = 1 To 10
- If zone = tabler(h) Then
- Put #2, Position2, tablem(h)
- Position2 = Position2 + Len(tablem(h))
- trouve = True
- h = 10
- End If
- Next h
- If Not trouve Then
- Put #2, Position2, zone
- Position2 = Position2 + Len(zone)
- End If
- End If
- Next g
- Close #2
- Wend
- Close #1
- MsgBox "TRAITEMENT TERMINE RESULTAT DANS C:\temp"
- End Sub
-
- Private Sub dir1_Change()
-
- End Sub
-
- Private Sub dir1_Click()
- For i = 0 To dir1.ListCount - 1
- If dir1.Selected(i) Then
- chemin = chemin + dir1.List(i) + "\"
- End If
-
- Next i
-
- dir1.Clear
- file1.Clear
- myname = Dir(chemin)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
- ' Ignore le répertoire courant et le répertoire
- ' contenant le répertoire courant.
- If myname <> "." And myname <> ".." Then
-
- ' Utilise une comparaison au niveau du bit pour
- ' vérifier que MyName est un répertoire.
-
- file1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- MyPath = chemin ' Définit le chemin d'accès.
- ' Extrait la première entrée.
- myname = Dir(MyPath, vbDirectory)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
-
- If (GetAttr(MyPath & myname) _
- And vbDirectory) = vbDirectory Then
- dir1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- UserForm1.Repaint
-
- End Sub
-
- Private Sub Label2_Click()
-
- End Sub
-
- Private Sub TextBox1_Change()
-
- End Sub
-
- Private Sub ListBox2_Click()
-
- End Sub
-
- Private Sub OptionButton1_Click()
- dir1.Clear
- file1.Clear
- chemin = "c:\"
- myname = Dir(chemin)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
- ' Ignore le répertoire courant et le répertoire
- ' contenant le répertoire courant.
- If myname <> "." And myname <> ".." Then
-
- ' Utilise une comparaison au niveau du bit pour
- ' vérifier que MyName est un répertoire.
-
- file1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- MyPath = chemin
- ' Extrait la première entrée.
- myname = Dir(MyPath, vbDirectory)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
-
- If (GetAttr(MyPath & myname) _
- And vbDirectory) = vbDirectory Then
- dir1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- End Sub
-
- Private Sub OptionButton2_Click()
- dir1.Clear
- file1.Clear
- chemin = "d:\"
- myname = Dir(chemin)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
- ' Ignore le répertoire courant et le répertoire
- ' contenant le répertoire courant.
- If myname <> "." And myname <> ".." Then
-
- ' Utilise une comparaison au niveau du bit pour
- ' vérifier que MyName est un répertoire.
-
- file1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- MyPath = chemin
- ' Extrait la première entrée.
- myname = Dir(MyPath, vbDirectory)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
-
- If (GetAttr(MyPath & myname) _
- And vbDirectory) = vbDirectory Then
- dir1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- End Sub
-
- Private Sub UserForm_Activate()
- '
- ' on travaille sur le disque c:
- '
- disque = "c:"
- MyPath = disque + "\" ' Définit le chemin d'accès.
- chemin = disque + "\"
- ' Extrait la première entrée.
- myname = Dir(MyPath)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
- ' Ignore le répertoire courant et le répertoire
- ' contenant le répertoire courant.
- If myname <> "." And myname <> ".." Then
-
- ' Utilise une comparaison au niveau du bit pour
- ' vérifier que MyName est un répertoire.
-
- file1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- MyPath = disque + "\" ' Définit le chemin d'accès.
- ' Extrait la première entrée.
- myname = Dir(MyPath, vbDirectory)
- nb = 1
- Do While myname <> "" ' Commence la boucle.
-
- If (GetAttr(MyPath & myname) _
- And vbDirectory) = vbDirectory Then
- dir1.AddItem (myname)
- End If
- myname = Dir ' Extrait l'entrée suivante.
- Loop
- End Sub
-
-
- Private Sub UserForm_Click()
- End Sub
-
- Private Sub Command1_Click()
- End Sub
-
-
-
- Function MKL(chiffre)
- '
- ' sp pour transformer un nombre en 4 caractères
- ' Note : nombre entier et positif
- '
- Dim x1 As Long, x2 As Long, x3 As Long
- x1 = 256# * 256# * 256#
- x2 = 256# * 256#
- x3 = 256#
- chiffre2 = chiffre
- a1$ = Chr(Int(chiffre2 / x1))
- chiffre2 = chiffre2 - Asc(a1$) * x1
- a2$ = Chr(Int(chiffre2 / x2))
- chiffre2 = chiffre2 - Asc(a2$) * x2
- a3$ = Chr(Int(chiffre2 / x3))
- chiffre2 = chiffre2 - Asc(a3$) * x3
- a4$ = Chr(Int(chiffre2))
- MKL = a1$ + a2$ + a3$ + a4$
-
- End Function
-
- Function CVL(zone As String)
- '
- ' sp pour transformer un nombre en 4 caractères
- ' Note : nombre entier et positif
- '
- Dim x1 As Long, x2 As Long, x3 As Long
- x1 = 256# * 256# * 256#
- x2 = 256# * 256#
- x3 = 256#
- CVL = Asc(Left(zone, 1)) * x1 + Asc(Mid(zone, 2, 1)) * x2 + Asc(Mid(zone, 3, 1)) * x3 + Asc(Right(zone, 1))
- End Function
-
-
-
Public chemin
Public disque
' PROGRAMME DE COMPRESSION DE DONNEES
' VIENT GERARD (FRANCE)
' Prévu pour le disque C:
' CECI EST UN EXEMPLE MAIS IL FAUDRAIT AMELIORER LA COMPRESSION
' ET LA RAPIDITE DU PROGRAMME ....
' En decompression on met le resultat dans c:\temp
'
' prévoir un écran avec deux zones de texte
' une zone de saisie pour le nom du fichier compressé
' une zone liste (dir1) contenant les repertoires
' une zone liste (file1) contenant les fichiers du repertoire
' deux boutons radios pour chosir le disque (c ou d)
' deux boutons commandes pour compresser ou decompresser
'
Private Sub CommandButton1_Click()
'
If Len(Dir(text1.Text)) <> 0 Then
Kill text1.Text
End If
Dim table(5000) As String, table2(5000) As Long, table3(255) As Long, table4(10) As String, table5(10) As Long, car As String, totalfichier As String, remplacement As String, cart As String, carr As String, resultat As String, ligne As String, ligne2 As String
Position = 1
tailletot = 0
For i = 0 To file1.ListCount - 1
If file1.Selected(i) Then
poslong = Position + 32
Open chemin + file1.List(i) For Binary As 1
taille = LOF(1)
tailletot = tailletot + taille
totalfichier = String(taille, " ")
Get #1, 1, totalfichier
Close 1
Label2.Caption = "TRAITEMENT CHOIX " + file1.List(i) + " TAILLE EN OCTETS : " + Str(taille)
blanc = String(128, " ")
'
' on écrit le nombre de caractère disponibles pour la répétition
'
g = 1
temp3 = ""
Erase table, table2, table3, table4, table5
pos = 1
maxix = 0
taille2 = taille + 1
While pos > 0
temp = Str(Int(g / taille * 100))
If temp <> temp3 Then
Label2.Caption = "TRAITEMENT LECTURE " + file1.List(i) + temp + "%"
UserForm1.Repaint
temp3 = temp
End If
fin = True
mot = ""
While fin
car = Mid(totalfichier, pos, 1)
pos = pos + 1
mot = mot + car
tp = Asc(car + " ")
table3(tp) = table3(tp) + 1
If Len(mot) = 4 Or car = "" Then fin = False
Wend
If pos > Len(totalfichier) Then pos = 0
If pos > 0 Then
If Len(mot) >= 2 Then
trouve = False
For h = 0 To maxix
If mot = table(h) Then
table2(h) = table2(h) + 1
h = maxix
trouve = True
End If
Next h
If trouve = False And maxix < 250 Then
maxix = maxix + 1
table(maxix) = mot
table2(maxix) = 1
End If
End If
g = pos
End If
Wend
'
' on tri determine les caracteres
' à répéter
'
tri = True
While tri
tri = False
For g = 0 To maxix
For h = g + 1 To maxix
If table2(g) * Len(table(g)) < table2(h) * Len(table(h)) Then
tt1 = table(g)
tt2 = table2(g)
table(g) = table(h)
table2(g) = table2(h)
table(h) = tt1
table2(h) = tt2
tri = True
End If
Next h
Next g
Wend
'
' tri des caracteres du moins vers le plus
' pour utiliser les caracteres de repetitions qui apparaissent
' le moins dans le fichier
'
For g = 0 To 10
table5(g) = 999999999#
Next g
For g = 0 To 255
For h = 0 To 10
If table5(h) > table3(g) Then
table5(h) = table3(g)
table4(h) = Chr(g)
h = 10
End If
Next h
Next g
Open text1.Text For Binary As 2
'
' on prepare les 4 octets de la longueur du fichier
'
ligne = MKL(0)
Put #2, Position, ligne
Position2 = Position
Position = Position + 4
'
' on ecrit le caractère de remplacement
'
ligne = table4(0)
Put #2, Position, ligne
Position = Position + 1
'
' on ecrit la longueur du nom de fichie reel
'
ligne = Chr(Len(Trim(file1.List(i))))
Put #2, Position, ligne
Position = Position + 1
'
' on ecrit le nom du fichier reel
'
ligne = Trim(file1.List(i))
Put #2, Position, ligne
Position = Position + Len(ligne)
'
' on ecrit les occurences des chaines
' 1 caractere de repetition
' 1 caractere pour la longueur de la zone repete
' la zone repete
'
For g = 0 To 9
mot = table(g)
ligne = table4(g + 1)
Put #2, Position, ligne
Position = Position + 1
ligne = Chr(Len(mot))
Put #2, Position, ligne
Position = Position + 1
ligne = mot
Put #2, Position, ligne
Position = Position + Len(ligne)
Next g
g = 1
carr = table4(0)
Position3 = Position
While g <= Len(totalfichier)
cart = Mid(totalfichier, g, 1)
temp = Str(Int(g / taille2 * 100))
If temp <> temp3 Then
Label2.Caption = "TRAITEMENT ECRITURE " + file1.List(i) + temp + "%"
UserForm1.Repaint
temp3 = temp
End If
For h = 0 To 9
mot = table4(h + 1)
If cart = mot Then
ligne = carr + mot
Put #2, Position, ligne
Position = Position + 2
g = g + 1
h = 99
Else
mot = table(h)
If mot <> "" Then
If Mid(totalfichier, g, Len(mot)) = mot Then
ligne = table4(h + 1)
Put #2, Position, ligne
Position = Position + 1
g = g + Len(mot)
h = 99
End If
End If
End If
Next h
If cart = carr Then
ligne = carr + cart
Put #2, Position, ligne
Position = Position + 2
g = g + 1
Else
If h < 99 Then
ligne = cart
Put #2, Position, ligne
Position = Position + 1
g = g + 1
End If
End If
Wend
ligne = MKL(Position - Position3)
Put #2, Position2, ligne
taillecomp = LOF(2)
Close #2
'
' on ecrit les caracteres de répétition
'
If taille > 0 Then Label2.Caption = file1.List(i) + "(" + Str(Int((Position - Position2) / Len(totalfichier) * 100)) + "%)"
End If
Next i
MsgBox "OK TRAITEMENT TERMINE TAILE AVANT EN OCTETS" + Str(tailletot) + " TAILLE APRES " + Str(taillecomp) + "(" + Str(Int((taillecomp / tailletot) * 100)) + "%)"
End Sub
Private Sub CommandButton2_Click()
Dim zone As String
Dim tabler(10) As String, tablel(10) As Long, tablem(10) As String
Open text1.Text For Binary As 1
Position = 1
While Position <= LOF(1)
zone = "xxxx"
Get #1, Position, zone
Position = Position + Len(zone)
longueurc = CVL(zone)
zone = "x"
Get #1, Position, zone
Position = Position + Len(zone)
carr = zone
Get #1, Position, zone
Position = Position + Len(zone)
lnom = Asc(zone)
zone = String(lnom, " ")
Get #1, Position, zone
Position = Position + Len(zone)
nomfic = zone
For g = 1 To 10
zone = "x"
Get #1, Position, zone
Position = Position + Len(zone)
tabler(g) = zone
Get #1, Position, zone
Position = Position + Len(zone)
tablel(g) = Asc(zone)
zone = String(tablel(g), "x")
Get #1, Position, zone
Position = Position + Len(zone)
tablem(g) = zone
Next g
'
' on remet le fichier dans temp
'
Label2.Caption = "TRAITEMENT DU FICHIER " + nomfic + Str(longueurc)
UserForm1.Repaint
Position2 = 1
Open "c:\temp\" + nomfic For Binary As 2
zone = "x"
taille2 = longueurc + 1
For g = 1 To longueurc
Get #1, Position, zone
Position = Position + Len(zone)
temp = Str(Int(Position / taille2 * 100))
If temp <> temp3 Then
Label2.Caption = "TRAITEMENT DU FICHIER " + nomfic + temp + "%"
UserForm1.Repaint
temp3 = temp
End If
If zone = carr Then
Get #1, Position, zone
Position = Position + Len(zone)
Put #2, Position2, zone
Position2 = Position2 + Len(zone)
Else
trouve = False
For h = 1 To 10
If zone = tabler(h) Then
Put #2, Position2, tablem(h)
Position2 = Position2 + Len(tablem(h))
trouve = True
h = 10
End If
Next h
If Not trouve Then
Put #2, Position2, zone
Position2 = Position2 + Len(zone)
End If
End If
Next g
Close #2
Wend
Close #1
MsgBox "TRAITEMENT TERMINE RESULTAT DANS C:\temp"
End Sub
Private Sub dir1_Change()
End Sub
Private Sub dir1_Click()
For i = 0 To dir1.ListCount - 1
If dir1.Selected(i) Then
chemin = chemin + dir1.List(i) + "\"
End If
Next i
dir1.Clear
file1.Clear
myname = Dir(chemin)
nb = 1
Do While myname <> "" ' Commence la boucle.
' Ignore le répertoire courant et le répertoire
' contenant le répertoire courant.
If myname <> "." And myname <> ".." Then
' Utilise une comparaison au niveau du bit pour
' vérifier que MyName est un répertoire.
file1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
MyPath = chemin ' Définit le chemin d'accès.
' Extrait la première entrée.
myname = Dir(MyPath, vbDirectory)
nb = 1
Do While myname <> "" ' Commence la boucle.
If (GetAttr(MyPath & myname) _
And vbDirectory) = vbDirectory Then
dir1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
UserForm1.Repaint
End Sub
Private Sub Label2_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub ListBox2_Click()
End Sub
Private Sub OptionButton1_Click()
dir1.Clear
file1.Clear
chemin = "c:\"
myname = Dir(chemin)
nb = 1
Do While myname <> "" ' Commence la boucle.
' Ignore le répertoire courant et le répertoire
' contenant le répertoire courant.
If myname <> "." And myname <> ".." Then
' Utilise une comparaison au niveau du bit pour
' vérifier que MyName est un répertoire.
file1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
MyPath = chemin
' Extrait la première entrée.
myname = Dir(MyPath, vbDirectory)
nb = 1
Do While myname <> "" ' Commence la boucle.
If (GetAttr(MyPath & myname) _
And vbDirectory) = vbDirectory Then
dir1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
End Sub
Private Sub OptionButton2_Click()
dir1.Clear
file1.Clear
chemin = "d:\"
myname = Dir(chemin)
nb = 1
Do While myname <> "" ' Commence la boucle.
' Ignore le répertoire courant et le répertoire
' contenant le répertoire courant.
If myname <> "." And myname <> ".." Then
' Utilise une comparaison au niveau du bit pour
' vérifier que MyName est un répertoire.
file1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
MyPath = chemin
' Extrait la première entrée.
myname = Dir(MyPath, vbDirectory)
nb = 1
Do While myname <> "" ' Commence la boucle.
If (GetAttr(MyPath & myname) _
And vbDirectory) = vbDirectory Then
dir1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
End Sub
Private Sub UserForm_Activate()
'
' on travaille sur le disque c:
'
disque = "c:"
MyPath = disque + "\" ' Définit le chemin d'accès.
chemin = disque + "\"
' Extrait la première entrée.
myname = Dir(MyPath)
nb = 1
Do While myname <> "" ' Commence la boucle.
' Ignore le répertoire courant et le répertoire
' contenant le répertoire courant.
If myname <> "." And myname <> ".." Then
' Utilise une comparaison au niveau du bit pour
' vérifier que MyName est un répertoire.
file1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
MyPath = disque + "\" ' Définit le chemin d'accès.
' Extrait la première entrée.
myname = Dir(MyPath, vbDirectory)
nb = 1
Do While myname <> "" ' Commence la boucle.
If (GetAttr(MyPath & myname) _
And vbDirectory) = vbDirectory Then
dir1.AddItem (myname)
End If
myname = Dir ' Extrait l'entrée suivante.
Loop
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub Command1_Click()
End Sub
Function MKL(chiffre)
'
' sp pour transformer un nombre en 4 caractères
' Note : nombre entier et positif
'
Dim x1 As Long, x2 As Long, x3 As Long
x1 = 256# * 256# * 256#
x2 = 256# * 256#
x3 = 256#
chiffre2 = chiffre
a1$ = Chr(Int(chiffre2 / x1))
chiffre2 = chiffre2 - Asc(a1$) * x1
a2$ = Chr(Int(chiffre2 / x2))
chiffre2 = chiffre2 - Asc(a2$) * x2
a3$ = Chr(Int(chiffre2 / x3))
chiffre2 = chiffre2 - Asc(a3$) * x3
a4$ = Chr(Int(chiffre2))
MKL = a1$ + a2$ + a3$ + a4$
End Function
Function CVL(zone As String)
'
' sp pour transformer un nombre en 4 caractères
' Note : nombre entier et positif
'
Dim x1 As Long, x2 As Long, x3 As Long
x1 = 256# * 256# * 256#
x2 = 256# * 256#
x3 = 256#
CVL = Asc(Left(zone, 1)) * x1 + Asc(Mid(zone, 2, 1)) * x2 + Asc(Mid(zone, 3, 1)) * x3 + Asc(Right(zone, 1))
End Function
Conclusion
Le principe : - Le programme lit le fichier à compresser. - Il analyse les caractères les moins utiliser et le plus utiliser. Il écrit un fichier compresser en se servant des caractères les moins présents pour code de répétition.
Sources du même auteur
Sources de la même categorie
DÉCOMPRESSER EN .NET PLUSIEURS FORMATS POPULAIRES D'ARCHIVAG...DÉCOMPRESSER EN .NET PLUSIEURS FORMATS POPULAIRES D'ARCHIVAGE (RAR, ZIP, CAB, 7Z, GZIP, TAR, ETC...) Ce code permet de décompresser beaucoup des formats d'archivage RAR, ZIP, CAB, GZIP, BZIP2, TAR, 7z et la liste n'est pas complète.
Ce code est des...
par NikatorS
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Compression TIFF multipages [ par fab2503 ]
Bonjour, Je réalise une appli qui utilise des fichiers tiff scannés et j'ai besoin de compresser ces images pour éviter de prendre trop de place. Po
Méga sécurité [ par Dragon ]
je suis en train de penser à créé un petit soft de stockage de fichier sur internet, comme plusieurs soft très lent :-)sauf que je veut mis prendre d`
compression [ par joflo ]
une question a 10 eurosje voudrais compresser un gros fichier mais en plusieurs zip(3 ou 4) et pouvoir reconstituer ensuite le fichier originalquelqu'
Compression de fichier en VBA [ par renocmoa ]
Bonjour, je voudrais pouvoir Zipper ou RARer un fichier en VBA j'ai bien trouvé des dll ou OCX pour dézipper mais pas pour compresser quelqu'un à un i
compression de fichier txt [ par jf_gabriel ]
Bonjour,pour une appli, je dois stocker pas mal d'information dans des fichiers TXT. Ceux-ci occupant pas mal de place disque, je cherche un script ou
Compression de fichier excel [ par cbr600fs ]
Bonjour,j'utilise VBA pour excel et j'aurai voulu savoir si il existait un code pour compresser des fichiers excel sans WinZip, mais en utilisnt le sy
Compression [ par eldim ]
Bonjour,Est-ce quelqu'un connait un programme zip qui vérifie si un fichier existe déja dans un zip et compare les versions avant d'ajouter
Compression GZip .NET 2.0 [ par EvilGost ]
Bonjour à tous les développeurs,je suis actuellement confronté à un problème. Pour mon appli, je dois compresser un répertoire complete, via GZip, int
archivage, concatenations de fichiers [ par fagol ]
Bonjours,Je fais un programme qui genere une quinzaine de fichiers.Aussi je souhaiterais gérer à l'enregistrement des resulats, (issus de mon programm
Concatenation de fichier, compression et autre idee [ par alligo ]
Bonjour à tousJ'ai un petit probleme sur un programme, c'est plus un probleme fondamental que purement de programmation:Mon programme doit gerer enorm
|
Derniers Blogs
TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|