- Visual Basic / VB.NET : Accéder au fichiers de n'importe quelle taille sans fso et sans open
- Lire une partie d'un fichier de n'importe quelle taille
- Envoyer n'importe quel fichier, de n'importe quelle taille par winsock
- Fichier utilsé par d'autre processus
- Visual Basic / VB.NET : Fichier ini + fonctions sauve position + taille fenetre, mettre val vite,...
Public Event ReadWizzardData(Data As String, Percent As Long)
Public Event ReadWizzardFinish()
Public Event Error(Number)
Private Mstop As Boolean
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 CloseHandle Lib "kernel32" (ByVal hObject 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 ReadFile Lib "kernel32" (ByVal hfile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hfile As Long, lpFileSizeHigh As Long) As Long
'Erreurs
' CannotOpenFile = 0
' Unknown = 666
' InvalidStartPosition = 1
' InvalidEndPosition = 2
' InvalidPakSize = 3
'\Public Sub Cancel()
Mstop = True
End Sub
Private Sub Clean(hand As Long)
Mstop = False
CloseHandle (hand)
End Sub
Function Read(File, Optional Pak_Size As Long 100000, Optional StartPos As Long 0, Optional EndPos As Long = 0) As Boolean
Dim handle As Long, Taille As Long
Mstop = False
handle = CreateFile(File, -2147483648#, 1 Or 2, ByVal 0&, 3, 0, 0)
If handle = -1 Then
RaiseEvent Error(0)
Exit Function
End If
Taille = GetFileSize(handle, 0)
If Pak_Size < 0 Then
RaiseEvent Error(3)
Clean handle
Exit Function
End If
If StartPos < 0 Or StartPos > Taille Then
RaiseEvent Error(1)
Clean handle
Exit Function
End If
If EndPos 0 Then EndPos Taille
If Taille = 0 Then
RaiseEvent Error(666)
Clean handle
Exit Function
End If
If EndPos < StartPos Or EndPos > Taille Then
Clean handle
RaiseEvent Error(2)
Exit Function
End If
If StartPos <> 0 Then
SetFilePointer handle, StartPos, 0, 0
End If
Dim rendu As Long, Texte As String
rendu = StartPos
Read = True
Do Until (rendu + Pak_Size) > EndPos Or Mstop = True
Texte = String$(Pak_Size, 0)
ReadFile handle, ByVal Texte, Len(Texte), 0, ByVal CLng(0)
rendu = rendu + Pak_Size
RaiseEvent ReadWizzardData(Texte, (rendu / Taille) * 100)
DoEvents
Loop
If Mstop = True Then Clean handle: Exit Function
rendu = EndPos - rendu
If rendu <> 0 Then
Texte = String$(rendu, 0)
ReadFile handle, ByVal Texte, Len(Texte), 0, ByVal CLng(0)
RaiseEvent ReadWizzardData(Texte, 100)
End If
Clean handle
RaiseEvent ReadWizzardFinish
End Function
Private Sub Class_Terminate()
Mstop = True
End Sub
si vous savez comment optimiser ça davantage, dites moi le svp. Pi je pense pas qu'il y a moyen d'ouvrir en binary à moins de convertir ce qu'on lit en binary.
Très intéressant ton code.
J'aimerais savoir s'il est possible de l'utiliser pour optimiser un find/replace (si possible en binary access) ?
j'aurais besoin de traiter des fichiers qui peuvent atteindre en moyenne 18 Mo