VBS: compression (zip) de fichiers (*.extension1, *.extension2)
Bonjour,
Je cherche à compresser certains fichiers (*.html, *.css etc.) de différents répertoires en un seul fichier zip.
Comment faire?
Ma 1ère tentative a été d'utiliser Chilkat, mais après 30j d'évaluation, c'est maintenant payant. Je dois trouver une autre méthode.
Celles vu sur forums ne correspondent pas à mes besoins.
Voilà mon code actuel (qui marche très bien si on a Chilkat...):
Code:
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| 'Script permettant de zipper les fichiers de baseSRC (et sous répertoires de manière récursive) dans un fichier sauvegardé dans baseDST
'declaration des 2 variables avec la methode arg()
String baseSRC, baseDST
Dim oArgs
If wscript.Arguments.length <> 2 Then
WScript.Echo "------------- Incorrect Number of Arguments -------------"
WScript.Quit
End if
Set oArgs=WScript.Arguments ' tableau d'arguments
baseSRC=WScript.Arguments(0) ' premier argument
baseDST=WScript.Arguments(1) ' second argument
if not isAFolder(baseSRC) then
WScript.Echo "------------- The " & baseSRC & " folder does NOT exist -------------"
WScript.Quit
End if
set zip = CreateObject("ChilkatZip2.ChilkatZip2")
zip.UnlockComponent "anything for 30-day trial"
' One last example -- combine DiscardPaths with PathPrefix
' with multiple calls to AppendFiles:
' Clear the zip object.
zip.NewZip baseDST & "master_new.zip"
'msgbox "Zip: " & baseDST & "master.zip"
zip.AppendFromDir = baseSRC
'take all the textual files
dim path
dim numDossier
numDossier = 1
dim recurse
recurse = true
do
Select case (numDossier)
case 1
path = "html\"
case 2
path = "css\"
end select
zip.AppendFiles path & "*.xml",recurse
zip.AppendFiles path & "*.txt",recurse
zip.AppendFiles path & "*.html",recurse
zip.AppendFiles path & "*.htm",recurse
zip.AppendFiles path & "*.js",recurse
zip.AppendFiles path & "*.xsl",recurse
zip.AppendFiles path & "*.css",recurse
zip.AppendFiles path & "*.gif",recurse
numDossier = numDossier + 1
loop while (numDossier < 3)
zip.AppendFiles "/html/*.gif",recurse
zip.AppendFiles "/html/*.jpg",recurse
success = zip.WriteZipAndClose()
If (success <> 1) Then
MsgBox zip.LastErrorText
WScript.Quit
End If
WScript.Quit
Function isAFolder(pathName) Dim isFold
isFold = false
Dim fso
Set fso=wscript.CreateObject("Scripting.FileSystemObject")
if fso.FolderExists(pathName) then
isFold = true
end if
isAFolder = isFold
End Function |
Comment faire autrement?
Choutlse31