Solved

Copying Multiple Files

Posted on 1998-12-29
3
166 Views
Last Modified: 2013-11-20
Is there a command which will copy Multiple files using a wild card?  I have tried
CopyFile("C:\\Source\\*.*", "C:\\Destination\\", FALSE);
and
CopyFile("C:\\Source\\*.ext", "C:\\Destination\\", FALSE);

Neither have worked.  On-line help does not say it won't work, and the VB version example uses my second example above.

Thanks,
J.R.
0
Comment
Question by:jrmcg
  • 2
3 Comments
 

Accepted Solution

by:
JoeDol earned 20 total points
ID: 1326913
This function works only on one file at a time, so you should include your call into a loop controlled by FindFirstFile() and FindNextFile() in order to scan all the files that match your criteria. For example:

WIN32_FIND_DATA pwfd;
HANDLE hFindFile = FindFirstFile("C:\\Source\\*.*", &pwfd);
if (hFile != INVALID_HANDLE_VALUE)
{
   BOOL rc;

   do
   {
      CopyFile(pwfd.cFileName, ...);

      rc = FindNextFile(hFindFile, &pwfd);
   }
   while (rc != FALSE);

   FindClose(hFindFile);
}
0
 
LVL 2

Author Comment

by:jrmcg
ID: 1326914
This will do the trick.  I still would like to know if there is a function that will copy wild cards.  I can't help but think that there is a function that will do this.  Do you know of one?

Like I said, this will get me through the problem I am having and is probably a better way of handling the copying anyway..

Thanks,
J.R.
0
 
LVL 2

Author Comment

by:jrmcg
ID: 1326915
Sorry, but there is still a problem....

I accepted before I tried it.

When I use the code you supplied, this is returned..
CString SourcePath = "C:\\Source\\Files\\*.*";
HANDLE hFile = FindFirstFile(SourcePath, &pwfd);
CString Destination = "C:\\Destination\\Files\\" + pwfd.cFileName";
if(hFile != INVALID_HANDLE_VALUE)
{
   CopyFile(pwfd.cFileName, Destination, FALSE);
}

pwfd.cFileName is equal to a    .    (dot) nothing else.
I know my paths are good and there are files in the source path.

What's wrong?

Thank-you
J.R.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 109
Expand macro to ask for filename column 8 37
WinWaitActive parameters 12 31
wait notify demo infinite loop 3 98
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now