65.9K
CodeProject is changing. Read more.
Home

Copy binary folder files

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.27/5 (11 votes)

Dec 26, 2003

viewsIcon

50050

downloadIcon

624

EZ methods to copy a complete folder, while filtering the filetypes as needed.

Introduction

I needed a dirty method for copying my image folder.

Just use: WriteFolder txtSRCPATH, txtDESTPATH

Option Explicit

Private Sub Form_Load()

End Sub

Private Sub cmdCOPY_Click()
    WriteFolder txtSRCPATH, txtDESTPATH
End Sub
Sub WriteFolder(ByVal fsrc As String, ByVal fdes As String)

Dim Buffer() As Byte
Dim fname As String

    fname = Dir(fsrc, vbArchive)

    Do While fname <> ""
    DoEvents
        If (InStr(1, fname, "jpeg", vbBinaryCompare) > 0 
Or InStr(1, fname, "gif", vbBinaryCompare) > 0) Then DoEvents WriteFile fdes & fname, ReadFile(fsrc & fname, Buffer()) End If DoEvents fname = Dir() DoEvents Loop End Sub Function ReadFile(fname As String, Buffer() As Byte) As Byte() Dim fh, flen As Long fh = FreeFile Open fname For Binary Access Read As #fh flen = LOF(fh) Buffer = InputB(flen, #fh) Close #fh ReadFile = Buffer() End Function Sub WriteFile(fname As String, Buffer() As Byte) Dim fh As Long fh = FreeFile Open fname For Binary Access Write As #fh Put #fh, , Buffer Close #fh End Sub

The WriteFolder method passes "jpeg" and "gif" files only. (You can change this as needed.)