copy files help 
Author Message
 copy files help

Can anyone help with the following:

I have a form with Drive1, Dir1, List1  &  Drive2, Dir2, List2  & Command1

I want to select an input  directory with Dir1, & an output directory with
Dir2, then click Command1
to copy all files, in all the directories below the directory selected in
Dir1, copy all files to the directory
i select in Dir2. I have the code to set up the directories, but i cannot
get the code to copy all files from each directory below wht i select
in Dir1.

For Example:

In Dir1 i select C:\INPUT
In Dir2 i select C:\OUTPUT

In the C:\INPUT directory is a number of directories named say as:

C:\INPUT\INPUT01
C:\INPUT\INPUT02
C:\INPUT\INPUT03
C:\INPUT\INPUT04
C:\INPUT\INPUT05

& so on, in each of these directories is a number of Tif images & data files
etc. All these files could also be copied  from a CD Rom so
will have read only attributes.

How can i copy all files from each individual directory using Command1 & if
possible to display the file names as they are copied or
some kind of progress bar.

I didn't make it clear above that when i copy all the files
from the input directory selected in Dir1 to the output directory in Dir2,
i need just the files (Tif & data files) copied to the output directory, not
the
actual directories copied as well, all the files are named uniquely, so file
names are not
a problem, i need all the files copied from Dir1 to a single directory
selected in Dir2.

Thanks again.

Thanks for any help.

Steve



Fri, 21 Nov 2003 04:22:06 GMT  
 copy files help

Quote:
> I have a form with Drive1, Dir1, List1  &  Drive2, Dir2, List2  & Command1

> I want to select an input  directory with Dir1, & an output directory with
> Dir2, then click Command1
> to copy all files, in all the directories below the directory selected in
> Dir1, copy all files to the directory
> i select in Dir2. I have the code to set up the directories, but i cannot
> get the code to copy all files from each directory below wht i select
> in Dir1.

> For Example:

> In Dir1 i select C:\INPUT
> In Dir2 i select C:\OUTPUT

> In the C:\INPUT directory is a number of directories named say as:

> C:\INPUT\INPUT01
> C:\INPUT\INPUT02
> C:\INPUT\INPUT03
> C:\INPUT\INPUT04
> C:\INPUT\INPUT05

> & so on, in each of these directories is a number of Tif images & data
files
> etc. All these files could also be copied  from a CD Rom so
> will have read only attributes.

> How can i copy all files from each individual directory using Command1 &
if
> possible to display the file names as they are copied or
> some kind of progress bar.

> I didn't make it clear above that when i copy all the files
> from the input directory selected in Dir1 to the output directory in Dir2,
> i need just the files (Tif & data files) copied to the output directory,
not
> the
> actual directories copied as well, all the files are named uniquely, so
file
> names are not
> a problem, i need all the files copied from Dir1 to a single directory
> selected in Dir2.

The Drive, Dir and FileList controls are useful for displaying files
and directories, but complicate operations that don't need the
graphical feedback--you would have to reset the positions of
the controls to get subordinate file listings--at a cost of performance.

The Dir$() function can be looped to generate these file lists, but
with some caveats.  Starter code looks like:

Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal sDest As String)
  Dim sFile As String
  Dim sDir As Variant
  Dim cSub As Collection

  'put source and dest directories into an expected format
  If Right$(sSource, 1) <> "\" Then
    sSource = sSource & "\"
  End If

  If Right$(sDest, 1) <> "\" Then
    sDest = sDest & "\"
  End If

  'create a cache for subdirectory names
  Set cSub = New Collection

  'look for files in the source
  sFile = Dir$(sSource & "*.*", vbHidden Or vbReadOnly Or vbSystem Or
vbDirectory)

  Do While Len(sFile) > 0
    If sFile <> "." And sFile <> ".." Then
      If ((GetAttr(sSource & sFile) And vbDirectory) = vbDirectory) Then
        'it's a directory
        'it would be nice if we could just recurse this function from here,
        'but Dir$ cannot be called recursively.
        cSub.Add sFile
      Else
        'it's a file
        FileCopy sSource & sFile, sDest & sFile
      End If
    End If

    sFile = Dir$()
  Loop

  'take care of the subdirectories
  For Each sDir In cSub
    CopyFilesEnMasse sSource & sDir, sDest
  Next sDir
End Sub

______________________

Alternatives to this approach:

Win API: FindFirst, FindNext - fast and can be called recursively
File System Objects: slower, but provides a nice object interface



Fri, 21 Nov 2003 10:57:02 GMT  
 copy files help
Thanks for the help, but as i am new to VB i don't really understand what i
do with this code, any more help would be much appreciated.

I can make it copy files from a single directory i select with Dir1, to
Dir2, but it only copies the contents of a single directory, not the
contents
of all directories below the directory selected in Dir1.

Thanks again


Quote:
> > I have a form with Drive1, Dir1, List1  &  Drive2, Dir2, List2  &
Command1

> > I want to select an input  directory with Dir1, & an output directory
with
> > Dir2, then click Command1
> > to copy all files, in all the directories below the directory selected
in
> > Dir1, copy all files to the directory
> > i select in Dir2. I have the code to set up the directories, but i
cannot
> > get the code to copy all files from each directory below wht i select
> > in Dir1.

> > For Example:

> > In Dir1 i select C:\INPUT
> > In Dir2 i select C:\OUTPUT

> > In the C:\INPUT directory is a number of directories named say as:

> > C:\INPUT\INPUT01
> > C:\INPUT\INPUT02
> > C:\INPUT\INPUT03
> > C:\INPUT\INPUT04
> > C:\INPUT\INPUT05

> > & so on, in each of these directories is a number of Tif images & data
> files
> > etc. All these files could also be copied  from a CD Rom so
> > will have read only attributes.

> > How can i copy all files from each individual directory using Command1 &
> if
> > possible to display the file names as they are copied or
> > some kind of progress bar.

> > I didn't make it clear above that when i copy all the files
> > from the input directory selected in Dir1 to the output directory in
Dir2,
> > i need just the files (Tif & data files) copied to the output directory,
> not
> > the
> > actual directories copied as well, all the files are named uniquely, so
> file
> > names are not
> > a problem, i need all the files copied from Dir1 to a single directory
> > selected in Dir2.

> The Drive, Dir and FileList controls are useful for displaying files
> and directories, but complicate operations that don't need the
> graphical feedback--you would have to reset the positions of
> the controls to get subordinate file listings--at a cost of performance.

> The Dir$() function can be looped to generate these file lists, but
> with some caveats.  Starter code looks like:

> Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal sDest As
String)
>   Dim sFile As String
>   Dim sDir As Variant
>   Dim cSub As Collection

>   'put source and dest directories into an expected format
>   If Right$(sSource, 1) <> "\" Then
>     sSource = sSource & "\"
>   End If

>   If Right$(sDest, 1) <> "\" Then
>     sDest = sDest & "\"
>   End If

>   'create a cache for subdirectory names
>   Set cSub = New Collection

>   'look for files in the source
>   sFile = Dir$(sSource & "*.*", vbHidden Or vbReadOnly Or vbSystem Or
> vbDirectory)

>   Do While Len(sFile) > 0
>     If sFile <> "." And sFile <> ".." Then
>       If ((GetAttr(sSource & sFile) And vbDirectory) = vbDirectory) Then
>         'it's a directory
>         'it would be nice if we could just recurse this function from
here,
>         'but Dir$ cannot be called recursively.
>         cSub.Add sFile
>       Else
>         'it's a file
>         FileCopy sSource & sFile, sDest & sFile
>       End If
>     End If

>     sFile = Dir$()
>   Loop

>   'take care of the subdirectories
>   For Each sDir In cSub
>     CopyFilesEnMasse sSource & sDir, sDest
>   Next sDir
> End Sub

> ______________________

> Alternatives to this approach:

> Win API: FindFirst, FindNext - fast and can be called recursively
> File System Objects: slower, but provides a nice object interface



Sat, 22 Nov 2003 07:06:33 GMT  
 copy files help

Quote:
> Thanks for the help, but as i am new to VB i don't really understand what
i
> do with this code, any more help would be much appreciated.

> I can make it copy files from a single directory i select with Dir1, to
> Dir2, but it only copies the contents of a single directory, not the
> contents
> of all directories below the directory selected in Dir1.

Just so I understand--you don't want to duplicate the subdirectory
structure.  Rather, you just want to copy those files into a single
destination directory?

Pop in the debug lines after the indicated lines of existing code:

Quote:
> >   'look for files in the source

         Debug.Print "EnMasse: " & sSource
         Debug.Print "      to: " & sDest

Quote:
> >         FileCopy sSource & sFile, sDest & sFile

              Debug.Print "Copy: " & sSource & sFile
              Debug.Print "     to: " & sDest & sFile

Quote:
> >     CopyFilesEnMasse sSource & sDir, sDest

          Debug.Print "Recurse: " & sSource & sDir

What's the output look like for what should be a file copy of
20-100 files with a few subdirectories?



Sat, 22 Nov 2003 08:25:27 GMT  
 copy files help
Thanks again for all your help so far, i have pasted the Debug lines into
the code
you gave me the other night, when i run the project nothing happens at all,
except for in the
VB Immediate window i get "Recurse :  followed by the source directory i
selected in Dir1,
 no files are copied at all, when i ran your code without the Debug lines
the files from the source directory
were copied to the destination directory, but it only copied the files from
that single directory, nono of the other files
were copied from the following directories.

You were correct when you said

"Just so I understand--you don't want to duplicate the subdirectory

Quote:
> structure.  Rather, you just want to copy those files into a single
> destination directory?"

I have pasted my current code at the end of this message for you to look at,
as you can see i have made

sSource=Dir1.path & "\"

sDest = Dir2.path

My directory structure looks like this:

In Dir1 i select C:\INPUT
 In Dir2 i select C:\OUTPUT

 In the C:\INPUT directory is a number of directories named say as:

 C:\INPUT\INPUT01
 C:\INPUT\INPUT02
 C:\INPUT\INPUT03
 C:\INPUT\INPUT04
 C:\INPUT\INPUT05

& so on, in each of these directories is a number of Tif images & data
files, approx. 100 files per directory, 99 tif images & 1 data file. when i
select
C:\INPUT with Dir1, i need the code to search through all the sub
directories
C:\INPUT\INPUT01, C:\INPUT\INPUT02 etc. & copy just the files in these
directories to
the directory selected in Dir2 - C:\OUTPUT, thus finishing up with all the
files from
C:\INPUT\INPUT01, C:\INPUT\INPUT02 etc. copied to C:\OUTPUT.

I do not know why this is not working, any further help would be much
appreciated:

Thanks again

Steve

------------------------------------------------

Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal sDest As String)
  Dim sFile As String
  Dim sDir As Variant
  Dim cSub As Collection

  End Sub

Private Sub Command2_Click()

'put source and dest directories into an expected format
  If Right$(sSource, 1) <> "\" Then
    sSource = Dir1.path & "\"
  End If

  If Right$(sDest, 1) <> "\" Then
    sDest = Dir2.path
  End If

  'create a cache for subdirectory names
  Set cSub = New Collection

  'look for files in the source
  Debug.Print "EnMasse: " & sSource
         Debug.Print "      to: " & sDest

  sFile = Dir$(sSource & "*.*", vbHidden Or vbReadOnly Or vbSystem Or
vbDirectory)

  Do While Len(sFile) > 0
    If sFile <> "." And sFile <> ".." Then
      If ((GetAttr(sSource & sFile) And vbDirectory) = vbDirectory) Then
        'it's a directory
        'it would be nice if we could just recurse this function from here,
        'but Dir$ cannot be called recursively.
        cSub.Add sFile
      Else
        'it's a file
        FileCopy sSource & sFile, sDest & sFile
        Debug.Print "Copy: " & sSource & sFile
              Debug.Print "     to: " & sDest & sFile

      End If
    End If

    sFile = Dir$()
  Loop

  'take care of the subdirectories
  For Each sDir In cSub
    CopyFilesEnMasse sSource & sDir, sDest

    Debug.Print "Recurse: " & sSource & sDir

  Next sDir

End Sub
----------------------------------------------------


Quote:
> > Thanks for the help, but as i am new to VB i don't really understand
what
> i
> > do with this code, any more help would be much appreciated.

> > I can make it copy files from a single directory i select with Dir1, to
> > Dir2, but it only copies the contents of a single directory, not the
> > contents
> > of all directories below the directory selected in Dir1.

> Just so I understand--you don't want to duplicate the subdirectory
> structure.  Rather, you just want to copy those files into a single
> destination directory?

> Pop in the debug lines after the indicated lines of existing code:

> > >   'look for files in the source
>          Debug.Print "EnMasse: " & sSource
>          Debug.Print "      to: " & sDest

> > >         FileCopy sSource & sFile, sDest & sFile
>               Debug.Print "Copy: " & sSource & sFile
>               Debug.Print "     to: " & sDest & sFile

> > >     CopyFilesEnMasse sSource & sDir, sDest
>           Debug.Print "Recurse: " & sSource & sDir

> What's the output look like for what should be a file copy of
> 20-100 files with a few subdirectories?



Sun, 23 Nov 2003 03:51:58 GMT  
 copy files help
There's got to be something radically wrong if adding
debug lines has changed the function.  Can you post
all of the related source code--your function as well
as how you're calling it.


Quote:
> Thanks again for all your help so far, i have pasted the Debug
lines into
> the code
> you gave me the other night, when i run the project nothing
happens at all,
> except for in the
> VB Immediate window i get "Recurse :  followed by the source
directory i
> selected in Dir1,
>  no files are copied at all, when i ran your code without the
Debug lines
> the files from the source directory
> were copied to the destination directory, but it only copied
the files from
> that single directory, nono of the other files
> were copied from the following directories.

> You were correct when you said

> "Just so I understand--you don't want to duplicate the
subdirectory
> > structure.  Rather, you just want to copy those files into a
single
> > destination directory?"

> I have pasted my current code at the end of this message for
you to look at,
> as you can see i have made

> sSource=Dir1.path & "\"

> sDest = Dir2.path

> My directory structure looks like this:

> In Dir1 i select C:\INPUT
>  In Dir2 i select C:\OUTPUT

>  In the C:\INPUT directory is a number of directories named
say as:

>  C:\INPUT\INPUT01
>  C:\INPUT\INPUT02
>  C:\INPUT\INPUT03
>  C:\INPUT\INPUT04
>  C:\INPUT\INPUT05

> & so on, in each of these directories is a number of Tif
images & data
> files, approx. 100 files per directory, 99 tif images & 1 data
file. when i
> select
> C:\INPUT with Dir1, i need the code to search through all the
sub
> directories
> C:\INPUT\INPUT01, C:\INPUT\INPUT02 etc. & copy just the files
in these
> directories to
> the directory selected in Dir2 - C:\OUTPUT, thus finishing up
with all the
> files from
> C:\INPUT\INPUT01, C:\INPUT\INPUT02 etc. copied to C:\OUTPUT.

> I do not know why this is not working, any further help would
be much
> appreciated:

> Thanks again

> Steve

> ------------------------------------------------

> Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal
sDest As String)
>   Dim sFile As String
>   Dim sDir As Variant
>   Dim cSub As Collection

>   End Sub

> Private Sub Command2_Click()

> 'put source and dest directories into an expected format
>   If Right$(sSource, 1) <> "\" Then
>     sSource = Dir1.path & "\"
>   End If

>   If Right$(sDest, 1) <> "\" Then
>     sDest = Dir2.path
>   End If

>   'create a cache for subdirectory names
>   Set cSub = New Collection

>   'look for files in the source
>   Debug.Print "EnMasse: " & sSource
>          Debug.Print "      to: " & sDest

>   sFile = Dir$(sSource & "*.*", vbHidden Or vbReadOnly Or
vbSystem Or
> vbDirectory)

>   Do While Len(sFile) > 0
>     If sFile <> "." And sFile <> ".." Then
>       If ((GetAttr(sSource & sFile) And vbDirectory) =
vbDirectory) Then
>         'it's a directory
>         'it would be nice if we could just recurse this
function from here,
>         'but Dir$ cannot be called recursively.
>         cSub.Add sFile
>       Else
>         'it's a file
>         FileCopy sSource & sFile, sDest & sFile
>         Debug.Print "Copy: " & sSource & sFile
>               Debug.Print "     to: " & sDest & sFile

>       End If
>     End If

>     sFile = Dir$()
>   Loop

>   'take care of the subdirectories
>   For Each sDir In cSub
>     CopyFilesEnMasse sSource & sDir, sDest

>     Debug.Print "Recurse: " & sSource & sDir

>   Next sDir

> End Sub
> ----------------------------------------------------



> > > Thanks for the help, but as i am new to VB i don't really
understand
> what
> > i
> > > do with this code, any more help would be much
appreciated.

> > > I can make it copy files from a single directory i select
with Dir1, to
> > > Dir2, but it only copies the contents of a single
directory, not the
> > > contents
> > > of all directories below the directory selected in Dir1.

> > Just so I understand--you don't want to duplicate the
subdirectory
> > structure.  Rather, you just want to copy those files into a
single
> > destination directory?

> > Pop in the debug lines after the indicated lines of existing
code:

> > > >   'look for files in the source
> >          Debug.Print "EnMasse: " & sSource
> >          Debug.Print "      to: " & sDest

> > > >         FileCopy sSource & sFile, sDest & sFile
> >               Debug.Print "Copy: " & sSource & sFile
> >               Debug.Print "     to: " & sDest & sFile

> > > >     CopyFilesEnMasse sSource & sDir, sDest
> >           Debug.Print "Recurse: " & sSource & sDir

> > What's the output look like for what should be a file copy
of
> > 20-100 files with a few subdirectories?



Sun, 23 Nov 2003 06:31:07 GMT  
 copy files help
Sorry Jon,

I have now realised that this Debug code has not changed the function at
all, I added another couple of lines
of code, which i intended to delete, but didn't. The function remains the
same with or without the Debug code,
the VB Immediate window just shows each file path & file name to & from. I
can still only get it to copy all files from a single
directory which i select with Dir1 & not all files from all directories to a
single output directory.

For example:

Dir1 displays:

C:\INPUT as the main directory, then C:\INPUT\INPUT001, INPUT002 & so on as
sub directories, how it works at the
moment is i have to dbl click on INPUT001 then Command2 & it copies all
files from INPUT001 to my output
directory, then i have to dbl click on INPUT002 & Command2 to make it copy
all files from INPUT002
to my output directory & so on. I want to select C:\INPUT with Dir1 as my
main directory, then click Command2
& all files from each sub directory copy to my output directory, just the
files copy, not the directories.

I hope this makes sense.

Thank you for any help you may be able to give me.

Steve


Quote:
> There's got to be something radically wrong if adding
> debug lines has changed the function.  Can you post
> all of the related source code--your function as well
> as how you're calling it.



> > Thanks again for all your help so far, i have pasted the Debug
> lines into
> > the code
> > you gave me the other night, when i run the project nothing
> happens at all,
> > except for in the
> > VB Immediate window i get "Recurse :  followed by the source
> directory i
> > selected in Dir1,
> >  no files are copied at all, when i ran your code without the
> Debug lines
> > the files from the source directory
> > were copied to the destination directory, but it only copied
> the files from
> > that single directory, nono of the other files
> > were copied from the following directories.

> > You were correct when you said

> > "Just so I understand--you don't want to duplicate the
> subdirectory
> > > structure.  Rather, you just want to copy those files into a
> single
> > > destination directory?"

> > I have pasted my current code at the end of this message for
> you to look at,
> > as you can see i have made

> > sSource=Dir1.path & "\"

> > sDest = Dir2.path

> > My directory structure looks like this:

> > In Dir1 i select C:\INPUT
> >  In Dir2 i select C:\OUTPUT

> >  In the C:\INPUT directory is a number of directories named
> say as:

> >  C:\INPUT\INPUT01
> >  C:\INPUT\INPUT02
> >  C:\INPUT\INPUT03
> >  C:\INPUT\INPUT04
> >  C:\INPUT\INPUT05

> > & so on, in each of these directories is a number of Tif
> images & data
> > files, approx. 100 files per directory, 99 tif images & 1 data
> file. when i
> > select
> > C:\INPUT with Dir1, i need the code to search through all the
> sub
> > directories
> > C:\INPUT\INPUT01, C:\INPUT\INPUT02 etc. & copy just the files
> in these
> > directories to
> > the directory selected in Dir2 - C:\OUTPUT, thus finishing up
> with all the
> > files from
> > C:\INPUT\INPUT01, C:\INPUT\INPUT02 etc. copied to C:\OUTPUT.

> > I do not know why this is not working, any further help would
> be much
> > appreciated:

> > Thanks again

> > Steve

> > ------------------------------------------------

> > Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal
> sDest As String)
> >   Dim sFile As String
> >   Dim sDir As Variant
> >   Dim cSub As Collection

> >   End Sub

> > Private Sub Command2_Click()

> > 'put source and dest directories into an expected format
> >   If Right$(sSource, 1) <> "\" Then
> >     sSource = Dir1.path & "\"
> >   End If

> >   If Right$(sDest, 1) <> "\" Then
> >     sDest = Dir2.path
> >   End If

> >   'create a cache for subdirectory names
> >   Set cSub = New Collection

> >   'look for files in the source
> >   Debug.Print "EnMasse: " & sSource
> >          Debug.Print "      to: " & sDest

> >   sFile = Dir$(sSource & "*.*", vbHidden Or vbReadOnly Or
> vbSystem Or
> > vbDirectory)

> >   Do While Len(sFile) > 0
> >     If sFile <> "." And sFile <> ".." Then
> >       If ((GetAttr(sSource & sFile) And vbDirectory) =
> vbDirectory) Then
> >         'it's a directory
> >         'it would be nice if we could just recurse this
> function from here,
> >         'but Dir$ cannot be called recursively.
> >         cSub.Add sFile
> >       Else
> >         'it's a file
> >         FileCopy sSource & sFile, sDest & sFile
> >         Debug.Print "Copy: " & sSource & sFile
> >               Debug.Print "     to: " & sDest & sFile

> >       End If
> >     End If

> >     sFile = Dir$()
> >   Loop

> >   'take care of the subdirectories
> >   For Each sDir In cSub
> >     CopyFilesEnMasse sSource & sDir, sDest

> >     Debug.Print "Recurse: " & sSource & sDir

> >   Next sDir

> > End Sub
> > ----------------------------------------------------



> > > > Thanks for the help, but as i am new to VB i don't really
> understand
> > what
> > > i
> > > > do with this code, any more help would be much
> appreciated.

> > > > I can make it copy files from a single directory i select
> with Dir1, to
> > > > Dir2, but it only copies the contents of a single
> directory, not the
> > > > contents
> > > > of all directories below the directory selected in Dir1.

> > > Just so I understand--you don't want to duplicate the
> subdirectory
> > > structure.  Rather, you just want to copy those files into a
> single
> > > destination directory?

> > > Pop in the debug lines after the indicated lines of existing
> code:

> > > > >   'look for files in the source
> > >          Debug.Print "EnMasse: " & sSource
> > >          Debug.Print "      to: " & sDest

> > > > >         FileCopy sSource & sFile, sDest & sFile
> > >               Debug.Print "Copy: " & sSource & sFile
> > >               Debug.Print "     to: " & sDest & sFile

> > > > >     CopyFilesEnMasse sSource & sDir, sDest
> > >           Debug.Print "Recurse: " & sSource & sDir

> > > What's the output look like for what should be a file copy
> of
> > > 20-100 files with a few subdirectories?



Sun, 23 Nov 2003 07:33:01 GMT  
 copy files help

Quote:
> I hope this makes sense.

I'm fairly certain I understand what you want:

\Source
    \Sub1
        a.txt
        b.txt
     \Sub2
        c.txt
     d.txt

Gets copied to:

\Dest
  a.txt
  b.txt
  c.txt
  d.txt

The provided code does this in an example I set up, so I suspect
that there's a difference in your code or parameters.

Please post the routine as you have it, and the code that calls it.
Also, the output of the immediate window with a matching set
of parameters.



Sun, 23 Nov 2003 10:05:33 GMT  
 copy files help
Hello Grinder,

Thanks again for all your help, below is my code as it stands now.

What you said in your last message was exactly what i require:
\Source

Quote:
>     \Sub1
>         a.txt
>         b.txt
>      \Sub2
>         c.txt
>      d.txt

> Gets copied to:

> \Dest
>   a.txt
>   b.txt
>   c.txt
>   d.txt

I can only get files to copy if i double click on each sub directory one at
a time,
i cannot get anything to happen if i select the main source directory, all i
get in the
immediate window is:

Copy: C:\Input\input001\001.tif
     to: C:\Output\001.tif

& so on for each file in sub directory C:\Input\input001.

Thanks again

------------------------------------------

Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal sDest As String)

   Dim sFile As String
   Dim sDir As Variant
   Dim cSub As Collection

   End Sub

Private Sub Command1_Click()

  'put source and dest directories into an expected format
    If Right$(sSource, 1) <> "\" Then
      sSource = Dir1.Path & "\"
    End If

    If Right$(sDest, 1) <> "\" Then
      sDest = Dir2.Path
    End If

    'create a cache for subdirectory names
    Set cSub = New Collection

    'look for files in the source
    Debug.Print "EnMasse: " & sSource
           Debug.Print "      to: " & sDest

    sFile = Dir$(sSource & "*.*", vbHidden Or vbReadOnly Or vbSystem Or
vbDirectory)

    Do While Len(sFile) > 0
      If sFile <> "." And sFile <> ".." Then
        If ((GetAttr(sSource & sFile) And vbDirectory) = vbDirectory) Then

          'it's a directory
          'it would be nice if we could just recurse this function from
here,

          'but Dir$ cannot be called recursively.
          cSub.Add sFile
        Else
          'it's a file
          FileCopy sSource & sFile, sDest & sFile
          Debug.Print "Copy: " & sSource & sFile
                Debug.Print "     to: " & sDest & sFile

        End If
      End If

      sFile = Dir$()
    Loop

    'take care of the subdirectories
    For Each sDir In cSub
      CopyFilesEnMasse sSource & sDir, sDest

      Debug.Print "Recurse: " & sSource & sDir

    Next sDir

  End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path

File1.SetFocus
End Sub

Private Sub Dir2_Change()
File2.Path = Dir2.Path

File2.SetFocus
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1
End Sub

Private Sub Drive2_Change()
Dir2.Path = Drive2
End Sub

----------------------------------------------------------

Quote:
> > I hope this makes sense.

> I'm fairly certain I understand what you want:

> \Source
>     \Sub1
>         a.txt
>         b.txt
>      \Sub2
>         c.txt
>      d.txt

> Gets copied to:

> \Dest
>   a.txt
>   b.txt
>   c.txt
>   d.txt

> The provided code does this in an example I set up, so I suspect
> that there's a difference in your code or parameters.

> Please post the routine as you have it, and the code that calls it.
> Also, the output of the immediate window with a matching set
> of parameters.



Mon, 24 Nov 2003 05:03:53 GMT  
 copy files help
Try this by pasting into a new project consisting of only a form containing
a single command button, two labels (Label1 & Label2), along with 2 Dir
controls (Dir1 & Dir2), as well as 2 FileList controls (File1 & File2). Be
sure to change the paths in the form load event, and be careful !!!

Option Explicit

Private Type SHFILEOPSTRUCT
  hwnd       As Long
  wFunc      As Long
  pFrom      As String
  pTo        As String
  fFlags     As Integer
  fAborted   As Boolean
  hNameMaps  As Long
  lpszProgressTitle  As String
End Type

Private Const FO_MOVE = &H1
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4

Private Const FOF_SILENT = &H4
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_FILESONLY = &H80&
Private Const FOF_SIMPLEPROGRESS = &H100

Private Declare Function SHFileOperation _
   Lib "shell32.dll" _
   Alias "SHFileOperationA" _
  (lpFileOp As SHFILEOPSTRUCT) As Long

Private Sub Command1_Click()

 'set some working variables
  Dim sSourcePath As String
  Dim sDestPath As String
  Dim SHFileOp As SHFILEOPSTRUCT

 'if nothing is yet selected, don't go any farther
  If (Dir1.Path <> "") Or (Dir2.Path <> "") Then

     'get the current paths from Dir controls
      sSourcePath = Dir1.Path
      sDestPath = Dir2.Path

     'Copy the files. The source path must
     'specify the file types to move via
     'wildcards (ie *.*, *.txt, etc).
     'The destination path can not
     'have wildcards. Both must be
     'terminated by a pair of nulls.
      sSourcePath = QualifyPath(Dir1.Path) & "*.*" & Chr$(0) & Chr$(0)
      sDestPath = QualifyPath(Dir2.Path) & Chr$(0) & Chr$(0)

      Label1.Caption = sSourcePath
      Label2.Caption = sDestPath
      Label1.Refresh
      Label2.Refresh

     'set up the options
      With SHFileOp
         .pFrom = sSourcePath
         .pTo = sDestPath
         .wFunc = FO_COPY   'what to do
         .fFlags = FOF_ALLOWUNDO  'any combination of FOF flags
      End With

     'copy'em
      Call SHFileOperation(SHFileOp)

   End If

 'refresh the file list
  Dir2.Refresh

End Sub

Private Function QualifyPath(tmpPath As String) As String

  If Right$(tmpPath, 1) = "\" Then
        QualifyPath = tmpPath
  Else: QualifyPath = tmpPath & "\"
  End If

End Function

Private Sub Dir1_Change()

   File1.Path = Dir1.Path
   File2.Path = Dir2.Path

End Sub

Private Sub Dir2_Change()

   File1.Path = Dir1.Path
   File2.Path = Dir2.Path

End Sub

Private Sub Form_Load()

   Dir1.Path = "d:\copysource"
   Dir2.Path = "d:\copydest"

   File1.Path = Dir1.Path
   File2.Path = Dir2.Path

End Sub

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/

Please respond only to the newsgroups so all can benefit.


: Can anyone help with the following:
:
: I have a form with Drive1, Dir1, List1  &  Drive2, Dir2, List2  & Command1
:
: I want to select an input  directory with Dir1, & an output directory with
: Dir2, then click Command1
: to copy all files, in all the directories below the directory selected in
: Dir1, copy all files to the directory
: i select in Dir2. I have the code to set up the directories, but i cannot
: get the code to copy all files from each directory below wht i select
: in Dir1.
:
: For Example:
:
: In Dir1 i select C:\INPUT
: In Dir2 i select C:\OUTPUT
:
: In the C:\INPUT directory is a number of directories named say as:
:
: C:\INPUT\INPUT01
: C:\INPUT\INPUT02
: C:\INPUT\INPUT03
: C:\INPUT\INPUT04
: C:\INPUT\INPUT05
:
: & so on, in each of these directories is a number of Tif images & data
files
: etc. All these files could also be copied  from a CD Rom so
: will have read only attributes.
:
: How can i copy all files from each individual directory using Command1 &
if
: possible to display the file names as they are copied or
: some kind of progress bar.
:
: I didn't make it clear above that when i copy all the files
: from the input directory selected in Dir1 to the output directory in Dir2,
: i need just the files (Tif & data files) copied to the output directory,
not
: the
: actual directories copied as well, all the files are named uniquely, so
file
: names are not
: a problem, i need all the files copied from Dir1 to a single directory
: selected in Dir2.
:
: Thanks again.
:
:
:
: Thanks for any help.
:
: Steve
:
:
:
:



Mon, 24 Nov 2003 06:33:30 GMT  
 copy files help

Quote:
> Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal sDest As
String)

>    Dim sFile As String
>    Dim sDir As Variant
>    Dim cSub As Collection

>    End Sub

> Private Sub Command1_Click()

>   'put source and dest directories into an expected format
>     If Right$(sSource, 1) <> "\" Then
>       sSource = Dir1.Path & "\"
>     End If

This doesn't look right--why did you split the function up?  Put
CopyFilesEnMasse back the way it was, and call it like this:

Private Sub Command1_Click()
  CopyFilesEnMasse Dir1.Path, Dir2.Path
End Sub



Mon, 24 Nov 2003 09:25:32 GMT  
 copy files help
Thankyou very much Randy,

I have tried your code, it copies all the files from the input directory i
select with Dir1 to the
output directory i select with Dir2, but it copies all the folders as well
as the files from the input directory, what i really need is just the files
from
each folder copied to the ouput directories, not the folders as well.

I need my project to look at the first sub directory below the input
directory selected with Dir1.Path, to copy all & only the files in this
first
sub directory to Dir2.Path, then to look at the next sub directory found &
copy all the files from that sub directory to Dir2.Path & so on, thus at the
end
of the process i have an output directory (Dir2.Path) containing only the
total number of files from Dir1.Path & not the folders.

I hope this makes things clear

Thanks again

Steve


Quote:
> Try this by pasting into a new project consisting of only a form
containing
> a single command button, two labels (Label1 & Label2), along with 2 Dir
> controls (Dir1 & Dir2), as well as 2 FileList controls (File1 & File2). Be
> sure to change the paths in the form load event, and be careful !!!

> Option Explicit

> Private Type SHFILEOPSTRUCT
>   hwnd       As Long
>   wFunc      As Long
>   pFrom      As String
>   pTo        As String
>   fFlags     As Integer
>   fAborted   As Boolean
>   hNameMaps  As Long
>   lpszProgressTitle  As String
> End Type

> Private Const FO_MOVE = &H1
> Private Const FO_COPY = &H2
> Private Const FO_DELETE = &H3
> Private Const FO_RENAME = &H4

> Private Const FOF_SILENT = &H4
> Private Const FOF_RENAMEONCOLLISION = &H8
> Private Const FOF_NOCONFIRMATION = &H10
> Private Const FOF_ALLOWUNDO = &H40
> Private Const FOF_FILESONLY = &H80&
> Private Const FOF_SIMPLEPROGRESS = &H100

> Private Declare Function SHFileOperation _
>    Lib "shell32.dll" _
>    Alias "SHFileOperationA" _
>   (lpFileOp As SHFILEOPSTRUCT) As Long

> Private Sub Command1_Click()

>  'set some working variables
>   Dim sSourcePath As String
>   Dim sDestPath As String
>   Dim SHFileOp As SHFILEOPSTRUCT

>  'if nothing is yet selected, don't go any farther
>   If (Dir1.Path <> "") Or (Dir2.Path <> "") Then

>      'get the current paths from Dir controls
>       sSourcePath = Dir1.Path
>       sDestPath = Dir2.Path

>      'Copy the files. The source path must
>      'specify the file types to move via
>      'wildcards (ie *.*, *.txt, etc).
>      'The destination path can not
>      'have wildcards. Both must be
>      'terminated by a pair of nulls.
>       sSourcePath = QualifyPath(Dir1.Path) & "*.*" & Chr$(0) & Chr$(0)
>       sDestPath = QualifyPath(Dir2.Path) & Chr$(0) & Chr$(0)

>       Label1.Caption = sSourcePath
>       Label2.Caption = sDestPath
>       Label1.Refresh
>       Label2.Refresh

>      'set up the options
>       With SHFileOp
>          .pFrom = sSourcePath
>          .pTo = sDestPath
>          .wFunc = FO_COPY   'what to do
>          .fFlags = FOF_ALLOWUNDO  'any combination of FOF flags
>       End With

>      'copy'em
>       Call SHFileOperation(SHFileOp)

>    End If

>  'refresh the file list
>   Dir2.Refresh

> End Sub

> Private Function QualifyPath(tmpPath As String) As String

>   If Right$(tmpPath, 1) = "\" Then
>         QualifyPath = tmpPath
>   Else: QualifyPath = tmpPath & "\"
>   End If

> End Function

> Private Sub Dir1_Change()

>    File1.Path = Dir1.Path
>    File2.Path = Dir2.Path

> End Sub

> Private Sub Dir2_Change()

>    File1.Path = Dir1.Path
>    File2.Path = Dir2.Path

> End Sub

> Private Sub Form_Load()

>    Dir1.Path = "d:\copysource"
>    Dir2.Path = "d:\copydest"

>    File1.Path = Dir1.Path
>    File2.Path = Dir2.Path

> End Sub

> --

> Randy Birch
> MVP Visual Basic

> http://www.mvps.org/vbnet/

> Please respond only to the newsgroups so all can benefit.



> : Can anyone help with the following:
> :
> : I have a form with Drive1, Dir1, List1  &  Drive2, Dir2, List2  &
Command1
> :
> : I want to select an input  directory with Dir1, & an output directory
with
> : Dir2, then click Command1
> : to copy all files, in all the directories below the directory selected
in
> : Dir1, copy all files to the directory
> : i select in Dir2. I have the code to set up the directories, but i
cannot
> : get the code to copy all files from each directory below wht i select
> : in Dir1.
> :
> : For Example:
> :
> : In Dir1 i select C:\INPUT
> : In Dir2 i select C:\OUTPUT
> :
> : In the C:\INPUT directory is a number of directories named say as:
> :
> : C:\INPUT\INPUT01
> : C:\INPUT\INPUT02
> : C:\INPUT\INPUT03
> : C:\INPUT\INPUT04
> : C:\INPUT\INPUT05
> :
> : & so on, in each of these directories is a number of Tif images & data
> files
> : etc. All these files could also be copied  from a CD Rom so
> : will have read only attributes.
> :
> : How can i copy all files from each individual directory using Command1 &
> if
> : possible to display the file names as they are copied or
> : some kind of progress bar.
> :
> : I didn't make it clear above that when i copy all the files
> : from the input directory selected in Dir1 to the output directory in
Dir2,
> : i need just the files (Tif & data files) copied to the output directory,
> not
> : the
> : actual directories copied as well, all the files are named uniquely, so
> file
> : names are not
> : a problem, i need all the files copied from Dir1 to a single directory
> : selected in Dir2.
> :
> : Thanks again.
> :
> :
> :
> : Thanks for any help.
> :
> : Steve
> :
> :
> :
> :



Tue, 25 Nov 2003 02:50:43 GMT  
 copy files help
Thanks again Grinder,

I have done what you said, but nothing happens when i select the input
directory with Dir1. The only way i can get files
to copy is by selecting each sub directory one at a time with Dir1, then it
copies just the files to Dir2, this would be perfect, if i could select
the main directory then it copied all the files from each sub directory to
the output directory (Dir2).

I don't know what i am doing wrong, is it possible for you to send me the
exact code which works for you, then i can compare
it to mine & work out where i am going wrong.

Thanks again

Steve


Quote:
> > Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal sDest As
> String)

> >    Dim sFile As String
> >    Dim sDir As Variant
> >    Dim cSub As Collection

> >    End Sub

> > Private Sub Command1_Click()

> >   'put source and dest directories into an expected format
> >     If Right$(sSource, 1) <> "\" Then
> >       sSource = Dir1.Path & "\"
> >     End If

> This doesn't look right--why did you split the function up?  Put
> CopyFilesEnMasse back the way it was, and call it like this:

> Private Sub Command1_Click()
>   CopyFilesEnMasse Dir1.Path, Dir2.Path
> End Sub



Tue, 25 Nov 2003 02:55:17 GMT  
 copy files help
Email your entire project to me zipped, and I'll take a look.


Quote:
> Thanks again Grinder,

> I have done what you said, but nothing happens when i select
the input
> directory with Dir1. The only way i can get files
> to copy is by selecting each sub directory one at a time with
Dir1, then it
> copies just the files to Dir2, this would be perfect, if i
could select
> the main directory then it copied all the files from each sub
directory to
> the output directory (Dir2).

> I don't know what i am doing wrong, is it possible for you to
send me the
> exact code which works for you, then i can compare
> it to mine & work out where i am going wrong.

> Thanks again

> Steve



> > > Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal
sDest As
> > String)

> > >    Dim sFile As String
> > >    Dim sDir As Variant
> > >    Dim cSub As Collection

> > >    End Sub

> > > Private Sub Command1_Click()

> > >   'put source and dest directories into an expected format
> > >     If Right$(sSource, 1) <> "\" Then
> > >       sSource = Dir1.Path & "\"
> > >     End If

> > This doesn't look right--why did you split the function up?
Put
> > CopyFilesEnMasse back the way it was, and call it like this:

> > Private Sub Command1_Click()
> >   CopyFilesEnMasse Dir1.Path, Dir2.Path
> > End Sub



Tue, 25 Nov 2003 05:52:46 GMT  
 copy files help
The project you sent me has not trace of the original
function I sent you.  At any rate remove the event
handler for Command1_Click.

Add these two procedures (one of which is an event
handler) to your form's code.  Be exact, don't "fix" it
as you go.

______

Private Sub Command1_Click()
  CopyFilesEnMasse File1.Path, File2.Path
End Sub

Public Sub CopyFilesEnMasse(ByVal sSource As String, ByVal sDest As String)
  Dim sFile As String
  Dim sDir As Variant
  Dim cSub As Collection

  'put source and dest directories into an expected format
  If Right$(sSource, 1) <> "\" Then
    sSource = sSource & "\"
  End If

  If Right$(sDest, 1) <> "\" Then
    sDest = sDest & "\"
  End If

  'create a cache for subdirectory names
  Set cSub = New Collection

  'look for files in the source
  sFile = Dir$(sSource & "*.*", vbHidden Or vbReadOnly Or vbSystem Or
vbDirectory)

  Do While Len(sFile) > 0
    If sFile <> "." And sFile <> ".." Then
      If ((GetAttr(sSource & sFile) And vbDirectory) = vbDirectory) Then
        'it's a directory
        'it would be nice if we could just recurse this function from here,
        'but Dir$ cannot be called recursively.
        cSub.Add sFile
      Else
        'it's a file
        FileCopy sSource & sFile, sDest & sFile
      End If
    End If

    sFile = Dir$()
  Loop

  'take care of the subdirectories
  For Each sDir In cSub
    CopyFilesEnMasse sSource & sDir, sDest
  Next sDir
End Sub



Tue, 25 Nov 2003 07:31:41 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Copying files help here...

2. Copying Files help Please

3. Copying Files....Help!!...SHFileOperation

4. Find a copy a file with File.Copy method

5. Help: Checking if *no* files in ListView are selected for file copying

6. how to use Volume Shadow Copy to copy an in use file

7. Copy a file in a folder and past the copy in another folder

8. Copy a bunch of files but can't cancel in the middle of copy

9. copy folder and copy files

10. Help to copy a file text

11. Need help finding method for copying files from Internet

12. Need help in error checking and copy multiple files

 

 
Powered by phpBB® Forum Software