• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Copying data

How do i copy a folder of .txt documents and subfolders to another destination

if you want more points ill will add them upon request

send no links code only
0
the_hood00
Asked:
the_hood00
  • 8
  • 3
  • 2
1 Solution
 
AaronReamsCommented:
You could always do it the easy way if you don't mind calling an external dos app.

ShellExecute(NULL,"open","xcopy","/S /C C:\\temp\\copy\\copy1\\*.txt C:\\temp\\copy\\copy2\\","",SW_SHOWMINIMIZED);


Hope this helps,
Aaron
0
 
jkrCommented:
I'd

use 'SHFileOperation()' instead, it comes with its own progress:

void CopyTree ( char* pszDst, char* pszSrc) {

SHFILEOPSTRUCT sfo;

ZeroMemory ( &sfo, sizeof ( sfo));

sfo.pFrom = pszSrc;
sfo.fTo = pszDst;
sfo.wFunc = FO_COPY;
sfo.fFlags = FOF_SIMPLEPROGRESS;
sfo.lpszProgressTitle = "Copying your files...";

SHFileOperation ( &sfo);
}

You can also turn off the progress if you want to.
0
 
AaronReamsCommented:
kewl, thanks for pointing out that function jkr.  I knew my way was kind of a hack but i threw it out there as a suggestion.

I'm curious about SHFileOperation.  I'll have to try it out tomorrow.  One question:  would he be able to only copy the txt files in the tree structure by passing in the pszSrc directory as <dir>\*.txt?

Cheers mate! -Aaron

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
the_hood00Author Commented:
         

           ok i think ill try the SHFileOperation but could you tell me what the variables are in your code example.
0
 
the_hood00Author Commented:
how do i add that code to a button
0
 
jkrCommented:
The variables are documented in the help files or at MSDN: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/structures/browseinfo.asp ("BROWSEINFO")

>> how do i add that code to a button

I assume that you mean execute that when a button is clicked? Call the function from your button handler.

BTW, don't know from the top of my head if wildcards will work.

0
 
the_hood00Author Commented:
i get this error
error C2039: 'fTo' : is not a member of '_SHFILEOPSTRUCTA'
        c:\program files\microsoft visual studio\vc98\include\shellapi.h(255) : see declaration of '_SHFILEOPSTRUCTA'

how do i fix this
0
 
the_hood00Author Commented:
nevermind i fixed it
0
 
the_hood00Author Commented:
when i try coping an .exe file i get a can not read from source file or disk even though the .exe exists and the path of it is correct
0
 
the_hood00Author Commented:
this is my code




CString CSclientextrac=("C:\\Client Version");
::CreateDirectory(CSclientextrac, NULL);
CSclientextrac=("C:\\Client Version\\dat");
::CreateDirectory(CSclientextrac, NULL);

CString CSfrom("C:\\Program Files\\Geoffism Studios\\set\\View.exe");
CString CSto("C:\\Client Version\\View.exe");



SHFILEOPSTRUCT sfo;

ZeroMemory ( &sfo, sizeof ( sfo));

sfo.pFrom = CSfrom;
sfo.pTo = CSto;
sfo.wFunc = FO_COPY;
sfo.fFlags = FOF_SIMPLEPROGRESS;
sfo.lpszProgressTitle = "Copying your files...";

SHFileOperation ( &sfo);
0
 
jkrCommented:
>>CString CSfrom("C:\\Program Files\\Geoffism Studios\\set\\View.exe");

This path contains spaces, yo you have to enclose that one in double quotes:

CString CSfrom("\"C:\\Program Files\\Geoffism Studios\\set\\View.exe\"");

The above should work.
0
 
the_hood00Author Commented:
and i want to change CSto so that it will copy the file to the desktop of the person running the program how do i do that
0
 
the_hood00Author Commented:
is there a diffrent way to delete a folder of files and subdirectories other then with SHFileOperation() and the string of the path to the folder has variables in it
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 8
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now