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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| Const ForReading = 1, ForWriting = 2, ForAppending = 8 'Parametre pour le zip
'msgbox ShowFolderList(source) 'Boite de dialogue contenat les resultats de la fonction
ShowFolderList(source)
Function ShowFolderList(strSource) 'variable affichant une liste de résultat
Dim fso, Dossiers, fic, fichiers, strListe, f, r
Dim Source, Destination, MyHex, MyBinary, i 'variables por la compression
Dim oApp, oFolder, oCTF, oFile 'variables por la compression
Dim TabNumFic()
source = "D:\test\" 'chemin ou sont les fichiers a zipper
Destination = "D:\save.zip" 'chemin de l'endroit ou va se situer le zip
Dim Zip
'Initialisation des variables pour le tri des fichiers
iDaysOld = 3
Set fso = CreateObject("Scripting.FileSystemObject")
Set Dossiers = fso.GetFolder(Source)
Set fic = Dossiers.Files
numFic = 0
cell = 0
'filtre pour ne recuperer que les fichiers ayant une date de modif > a 3 jours et ayant une extension .log
For Each fichiers In fic
If fichiers.DateLastModified < (Date() - iDaysOld) and Right(fichiers.ShortName,3) = "TXT" then
'Set f = fso.GetFile(fichiers)
cell = cell + 1
ReDim Preserve TabNumFic(2, cell)
TabNumFic(1, cell) = numFic
TabNumFic(2, cell) = fichiers.Name
'wscript.echo numFic
wscript.echo fichiers.Name
end if
numFic = numFic + 1
Next
'wscript.echo "Debut"
For i = 1 to ubound(TabNumFic)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim j
Dim oShell
Dim oFileSys
Set shell = CreateObject("WScript.Shell")
WinzipPath=shell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winzip.exe\")
wscript.echo WinzipPath
Source = "D:\test\"
Destination = "D:\" & TabNumFic(2,i) & ".zip"
'MyHex = _
'Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
'For j = 0 To UBound(MyHex)
'MyBinary = MyBinary & Chr(MyHex(j))
'Next
Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")
ZipName= TabNumFic(2,i)
'Creation du zip
'Set oCTF = oFileSys.CreateTextFile(Destination, True)
'oCTF.Write MyBinary
'oCTF.Close
'Set oCTF = Nothing
nomcmd=WinzipPath & " -min -a -r -hs " & ZipName & " " & source & TabNumFic(2,i)
shell.Run nomcmd, SW_SHOWNORMAL,true
If fso.FileExists(ZipName) Then
set f=fso.GetFile(ZipName)
s="Le fichier """ & f.name & """ de " & f.Size & " octets a été créé" & VBCRLF
s=s & "dans le dossier """ & f.ParentFolder & """" & VBCRLF
wscript.echo s
End If
Set oApp = CreateObject("Shell.Application")
Set oFolder = oApp.NameSpace(Source)
'If Not oFolder Is Nothing Then
'wscript.echo TabNumFic(2,i)
'oApp.NameSpace(Destination).CopyHere oFolder.Items.Item(TabNumFic(2,i))
'wScript.Sleep 5000
'Set oFile = Nothing
'On Error Resume Next
'Do While (oFile Is Nothing)
'Attention: provoque une erreur 70 si un des fichiers à zipper
'est toujours ouvert.
'Set oFile = oFileSys.OpenTextFile(Destination, ForAppending, False)
'If Err.Number <> 0 Then
'Err.Clear
'wScript.Sleep 3000
'End If
'Loop
'End If
Set oFile = Nothing
Set oFileSys = Nothing
Set FSys = CreateObject("Scripting.FileSystemObject")
Set MonFic = FSys.GetFile("D:\" & TabNumFic(2,i) & ".zip")
MonFic.Copy "D:\test\", True
Set FSys = CreateObject("Scripting.FileSystemObject")
Set MonFic = FSys.GetFile("D:\" & TabNumFic(2,i) & ".zip")
monfic.delete
next
Set fso = Nothing
Set Dossiers = Nothing
Set fic = Nothing
Set f = Nothing
End Function |
Partager