Link to home
Create AccountLog in
Avatar of CSecurity
CSecurityFlag for Iran, Islamic Republic of

asked on

problem in copy a folder in Thread

Hello
i'm developing a application that in a thread, I wanna copy a folder (include all files and sub directories) to another and I found this:

https://www.experts-exchange.com/questions/20982249/Copy-Folders-in-C.html

as "Assisted Solution"s comment (AlexFM), first I use memset() to fill all my char array to NULL char ('\0') and then, when I use strcpy() the function works but after using strcpy(), I should use strcat() for append some text to my char array. when I use strcat(), the function does not work!!!! (so strange)
what should I do?
thank you very much
char from[255], to[255];
 
memset(from,0,255);
memset(to,0,255);
 
strcpy(from,drive_letter); //drive_letter contain a folder path
 
strcpy(to,ini_path); //ini_path contain another folder path
strcat(to,"\\");
strcat(to,volume); //volume contain a name for folder-name
 
CopyFolder(from,to);

Open in new window

Avatar of CSecurity
CSecurity
Flag of Iran, Islamic Republic of image

ASKER

and function return 1026
I don't see a reason to use memset()
What do you mean with strcat() doesn't work?
Avatar of jkr
Try to outut the final values to chek cwhether they are correct, e.g.
char from[255], to[255];
 
memset(from,0,255);
memset(to,0,255);
 
strcpy(from,drive_letter); //drive_letter contain a folder path
 
strcpy(to,ini_path); //ini_path contain another folder path
strcat(to,"\\");
strcat(to,volume); //volume contain a name for folder-name
 
MessageBoxA(NULL, from, "Copying from:", MB_OK);
 
MessageBoxA(NULL, to, "Copying to:", MB_OK);
 
CopyFolder(from,to);

Open in new window

Avatar of llman
llman

Can you post the variable values for drive_letter, ini_path, and volume?

Did the directory separator ("\") get escaped within drive_letter and ini_path?

ohh! I found out the problem! the function that copies a folder, works correctly when I give it a folder path but I wanna copy a drive! when i give the function this parameters, doesn't work:

CopyFolder("h:\\","f:\\test");  //can not copy drive

well, now i should get files in drive and get all folders and give all folder to CopyFolder() function. now, the problem is get files in a drive and get all foders to give all folders to CopyFolder function. how can I get files and folders?
thanks you very much
What is the definition of CopyFolder?
Yes, but have you checked whether the from/to paths are built correctly?
yes, I'm sure because CopyFolder("h:\\","f:\\test"); doesnt work
What HRESULT do you get from 'SHFileOperation()'?
hr = 1026
(SUCCEEDED(hr)) = 1 //   I mean function returns 1
That's odd - this is not a valid HRESULT code...
ASKER CERTIFIED SOLUTION
Avatar of llman
llman

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
thank you very much
your link was useful ;)
CopyFolder("h:\\*.*","f:\\test"); //   *.* should be end of the source char array

thank you again