Results 1 to 4 of 4

Thread: having problems with filecopy and debugging

  1. #1
    Guest
    I am working on a pretty small program but am having some problems making it copy th files, it always says file not found. I am pretty new to VB so I am not sure what I am doing wrong. Thanks!

    Dim DirectoryPath As String, DirPath As String
    DirectoryPath = "c:\saved\" & Text1.Text
    DirPath = "c:\siscd\photos\*.*"

    MkDir DirectoryPath
    'FileCopy DirPath, DirectoryPath
    FileCopy "c:\siscd\photos\*.*", DirectoryPath

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You can't just pass it *.*
    You have to loop trough each file in the dir and copy it.
    You know how to loop trough a dir for all files?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Guest
    I am not sure how to loop through each file, is that the easiest way to do something like this? Can you let me know how to do the loop? Thanks!

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    kedaman wrote an excellent routine for doing this:

    Code:
    'CODE FROM KEDAMAN
    'Toss this in a UserControl:
    
    Option Explicit
    Public BarTimer As Long
    Event Filecatch(File As String, path As String, level As Integer)
    Event Direcatch(dire As String, path As String, level As Integer)
    Public curlevel%
    Public filemax
    Public Totalb$
    Public diremax
    Public tid
    Public Directory$
    Public tids As Long
    Public Waiter As Long
    Sub explore(startdir As String, Optional pauses = 100)
    tids = Timer
    filemax = 0: diremax = 0: Totalb = 0: curlevel = 0
    If Right(startdir, 1) <> "\" Then startdir = startdir & "\"
        ListSubDirs startdir, pauses
    
    tid = Timer - tids
    End Sub
    
    Sub ListSubDirs(path As String, pauses)
    Dim i, dmax, dirname As String, dire() As String   ' Declare variables.
    dirname = Dir(path, 63) ' Get first directory name.
    Do While dirname <> ""
    If dirname <> "." And dirname <> ".." Then
    If Int(GetAttr(path + dirname) / 16) Mod 2 = 1 Then
                                                                
    If (dmax Mod 10) = 0 Then
    ReDim Preserve dire(dmax + 10)    ' Resize the array.
    End If
    diremax = diremax + 1: dmax = dmax + 1
    dire(dmax) = dirname
    RaiseEvent Direcatch(dirname, path, curlevel)
    Else
    filemax = filemax + 1
    RaiseEvent Filecatch(dirname, path, curlevel)
    End If
    End If
    dirname = Dir   ' Get another directory name.
    Waiter = Waiter + 1: If Waiter Mod (pauses) = 1 Then DoEvents
    Loop
    For i = 1 To dmax
    curlevel = curlevel + 1
    ListSubDirs path & dire(i) & "\", pauses
    Next i
    curlevel = curlevel - 1
    End Sub
    
    
    'and on the form use this:
    
    
    Private Sub UserControl11_Filecatch(File As String, Path As String, level As Integer)
    Debug.Print Path & File 'Print all the files to the Debug window
    End If
    End Sub
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width