Trying to get my App to copy files with wildcards

This is a discussion on Trying to get my App to copy files with wildcards within the Windows Programming forums, part of the Platform Specific Boards category; (Using MS Visual C++ 6.0) I want to enable my application to copy files after I click a button. I ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Smile Trying to get my App to copy files with wildcards

    (Using MS Visual C++ 6.0)

    I want to enable my application to copy files after I click a button.

    I have tried the Shell function CopyFile, with no success. All I really need it to do is, copy all C:\windows\system\*.DLL to C:\back\system , saving them with their origonal names and file attributes.

    I tried spawning Xcopy.exe (Gawd, the horror!), sure it worked, but it is extremely non-optimal.

    Any suggestions on ways I could accomplish this, let me know please.

    (Note: I know how to link the function to clicking a button, so no help is needed there. Just need a function that will allow me to use wildcards to copy files, and how to use it.)

    Thank you much. In the mean time, I will search more...

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    23
    Try this one:

    Code:
    int  CopyAllFiles (
     char   *wildStr,
     char   *srcPath,
     char   *dstPath
    )
    {
       HANDLE           hf;
       BOOL             goFlag = FALSE;
       int              reply;
       WIN32_FIND_DATA  ffData;
       char             srcFile[MAX_PATH], dstFile[MAX_PATH];
    
       sprintf (srcFile, "%s\\%s", srcPath, wildStr);
       hf = FindFirstFile (srcFile, &ffData);
    
       for (goFlag=(hf!=INVALID_HANDLE_VALUE); goFlag; goFlag=FindNextFile(hf, &ffData))  {
          if (ffData.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE)  {
             sprintf (srcFile, "%s\\%s", srcPath, ffData.cFileName);
             sprintf (dstFile, "%s\\%s", dstPath, ffData.cFileName);
             reply = CopyFile (srcFile, dstFile, TRUE);
          }
       }
    
       if (hf!=INVALID_HANDLE_VALUE)
          FindClose (hf);
          
       return (0);
    }
    Call it like this:
    CopyAllFiles ("*.exe", "C:\\Foo", "D:\\Bar");

    Works for me. See on MSDN what third param of CopyFile() does and do whatever you want about it.
    Last edited by Delf; 09-28-2005 at 05:18 AM.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can also use SHFileOperation. The fFlags member can be used to control various aspects of the operations such as whether a progress dialog is shown.
    Code:
    SHFILEOPSTRUCT op = { 0 };
    
    op.hwnd   = hwnd;
    op.wFunc  = FO_COPY;
    op.pFrom  = TEXT("C:\\windows\\system\\*.dll\0");
    op.pTo    = TEXT("C:\\back\\system\0");
    op.fFlags = 0;
    
    SHFileOperation(&op);

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Nice, thank you!

    Thanks for the help, pretty easy to understand! Yeah that shellfileop thingy was tough for me to get, MS MSDN library online is like, helpful.......................IF you can find the right pages! I keep poping up to windows CE pages and stuff that isnt even related.... one page gives me functions with _underscores, and one doesnt........


    ................ahhhh the horror!

    Gonna have to break down and buy some books again.

    Anyhow, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  2. Files and wildcards
    By MacNilly in forum C Programming
    Replies: 3
    Last Post: 08-11-2007, 04:42 PM
  3. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 09:12 PM
  4. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 11:15 AM
  5. C function to copy files?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-11-2001, 02:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21