En VB comment effacer des données à la fin d'un fichier sans le dupliquer

yocrita Messages postés 21 Date d'inscription dimanche 25 juillet 2004 Statut Membre Dernière intervention 17 août 2007 - 24 févr. 2005 à 18:16
yocrita Messages postés 21 Date d'inscription dimanche 25 juillet 2004 Statut Membre Dernière intervention 17 août 2007 - 25 févr. 2005 à 08:09
voilà, la question est dans le sujet !
En fait je crypte un fichier (que j'ai ouvert en binaire) et je rajoute à la fin "a été crypté" pour ne pas pouvoir le refaire par dessus.

cela marche tres bien en fesant "put #n, LOF(n) + 1 , "a été crypté"
maintenant quand je décrypte je veux enlever "a été crypté" mais sans créer un autre fichier car je ne crypte et decrypte pas tout le fichier mais seulement une petite partie pour des raisons de rapidité.

merci de votre aide.

3 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
24 févr. 2005 à 18:48
cherche L'api SetFilePointer

Daniel
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
24 févr. 2005 à 19:37
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const OPEN_EXISTING = 3
Const OPEN_ALWAYS = 4
Const FILE_BEGIN = 0
Const FILE_CURRENT = 1
Const FILE_END = 2

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long

Private Declare Function SetFilePointer Lib "kernel32" _
(ByVal hFile As Long, ByVal lDistanceToMove As Long, _
lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Private Sub Command1_Click()

Dim Path As String
Dim hFile As Long

Path = "C:\...\Fichier.txt"
hFile = CreateFile(Path, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, 0, 0)

If hFile = -1 Then
MsgBox "Fichier Absent"
Exit Sub
End If

'enlever 2 caractères à la fin
SetFilePointer hFile, -2&, -1&, FILE_END
CloseHandle hFile


End Sub

Daniel
0
yocrita Messages postés 21 Date d'inscription dimanche 25 juillet 2004 Statut Membre Dernière intervention 17 août 2007 18
25 févr. 2005 à 08:09
merci Daniel je vais essayer !
0
Rejoignez-nous