Raul duke
Messages postés70Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention17 mai 2019
-
24 avril 2007 à 11:07
Raul duke
Messages postés70Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention17 mai 2019
-
25 avril 2007 à 11:15
bjr a tous,
voila, je creer une appli qui extrait des fichiers texte. j'aimerais pouvoir, a la fin d'un traitement de fichier, l'envoyer vers un zip.
l'appli tourne en permanence sur le reseau, j'ai donc besoin de verifier la taille du zip, afin d'en creer un nouveau s'il est trop volumineux.
j'utilise VS2003/framework 1.1/C1studioNet
Sub ZipZip(ByVal nomZip As String, ByVal FicAZipper As String)
Dim sZip As C1ZipFile
Dim zipInfo As FileInfo
Dim s_Date As String
If zipInfo.Length > 2000000 Then
File.Move(nomZip, CheminFicSauvegarde & "Flux " & s_Date & ".zip")
File.Create(nomZip)
MsgBox("OK creation")
End If
zipInfo = Nothing
sZip = New C1ZipFile
sZip.Open(nomZip) ' err"la reférence d'un objet n'est pas def a l'instance d'un objet"
Try
sZip.OpenBatch()
sZip.Entries.Add(FicAZipper)
sZip.CloseBatch()
MsgBox("OK ajout")
Catch ex As Exception
MsgBox(ex.Message)
Finally
sZip.CloseBatch()
End Try
End Sub
le code suivant fonctionne sauf dans les deux cas suivant :
- lorsque le fichier zip("nomZip") est vide
- lorsque qu'un nouveau fichier("nomZip") est créer
--> l'appli plante alors au niveau de (sZip.Open(nomZip))
Raul duke
Messages postés70Date d'inscriptionvendredi 16 décembre 2005StatutMembreDernière intervention17 mai 20192 25 avril 2007 à 11:15
bidouille...
cela marche lorsque le fichier zip n'est pas vide :
Sub ZipZip(ByVal nomZip As String, ByVal FicAZipper As String)
Dim sZip As C1ZipFile
Dim zipInfo As FileInfo
Dim s_Date As String s_Date = CStr(TimeOfDay.Now.ToShortDateString) & " " & CStr(TimeOfDay.Now.ToShortTimeString)
s_Date = s_Date.Replace("/", "-")
s_Date = s_Date.Replace(":", "h")
zipInfo = New FileInfo(nomZip)
If zipInfo.Length > 2000000 Then
File.Move(nomZip, CheminFicSauvegarde & "Flux " & s_Date & ".zip")
File.Create(CheminFicSauvegarde & "src.zip") 'src.zip = zip contenant une entrée, vide ou non.
End If
zipInfo = Nothing
sZip = New C1ZipFile
<gras>sZip.Open(nomZip) 'fonctionne seulement si le zip contient au moins une entrée</gras>
Try
sZip.OpenBatch()
sZip.Entries.Add(FicAZipper)
File.delete(FicAZipper)
sZip.CloseBatch()
MsgBox("OK ajout")
Catch ex As Exception
MsgBox(ex.Message)
Finally
sZip.CloseBatch()
End Try
End Sub
'ajouter C1.C1zip.dll ds le \bin
voila c plus une astuce qu'une véritable solution, cela permet quand meme a mon appli de tourner correctement.
je reste a la recherche d'une méthode pour ajouter des entrées dans un fichier zip VIDE ! ouvrir un fichier zip VIDE !