Folder/Directory copying in Builder c++

Can anyone help me with some code to copy a whole directory/file.
eg. if I point a path to "c: emp" I want to copy everything in that folder temp to a destination specified.

thanx

Comments

  • : Can anyone help me with some code to copy a whole directory/file.
    : eg. if I point a path to "c: emp" I want to copy everything in that folder temp to a destination specified.
    :
    : thanx
    :
    :

    copy them one at a time. use _findfirst() and _findnext() to determine the file names, then use Win32 API function CopyFile() to do the heavy stuff.
  • ok, will do thanx.

    but: In my c: emp folder there are other folders as well,
    what do I do now?

    i would so mch appreciate it if you could mail me
    a unit because i don't have any idea what to include in my
    header files? (deobotha@lantic.net)

    Thank you again for your time.

    Pompoei
  • Yay someone asked a question on one of the only things I know lol. I am working on a backup program so I am using alot of the windows files commands, copying moving etc.

    Ok, for your first post, to copy whole folders (directories) you can use the shfileoperation structure, which u can copy, move, delete folders(dirs) and you get some flags to customize exactly what you want.

    this is the msdn page on it http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/structures/shfileopstruct.asp

    and I can give you a sample code if need be, but I would suggest what was suggested already, to use the CopyFile command because you can customize exactly what it does alot better.

    As far as the subfolders, those are a bit tricky when your first trying it out, they will appear as . .. ... etc for each subfolder. Since your going to have to put the copyfile command into a loop (to copy more then 1 file) this is what I ended up doing:
    [code]
    if( strcmp(FindFileData.cFileName,".") != 0 && // Gets rid of
    strcmp(FindFileData.cFileName,"..") != 0 ) // sub folder dots
    [/code]

    I can give u more sample code if need be.


  • [b][red]This message was edited by dwccgc at 2004-8-11 11:3:10[/red][/b][hr]
    :use the CopyFile command because you can customize exactly what
    :it does alot better.

    [blue]
    I do not agree.

    It all depends on what you are trying to do. If you have a user interface like a backup program then Shfileoperation could be a better option.

    1) It provides a dialog box with a progress bar. The worst thing in the world is for your program to appear to be doing nothing when a process is being executed.

    2) It can prompt you to overwrite an existing file if one exist.

    3) During a move, copy, or rename operation you can give the file a new name if a file with the target name already exists.

    4) It gives you the possibility to [b]undo[/b].

    and more...

    It all depends on what you are doing. I would not say that CopyFile is better than Shfileoperation.
    [blue]


  • : It all depends on what you are doing. I would not
    : say that CopyFile is better than Shfileoperation.

    Right. CopyFile is 1000 times more primitive. SHFileOperation is the same routine used by Windows explorer -- it will do the right thing, all the right things, things you may not even thing about now, things you may not even [italic]know[/italic] about.
  • well, I like it better, certainly gives me less problems, and some of the flags dont even work well, like theres a flag to make it not ask you to create a directory if it doesnt exists, to just go ahead and do it, but if you dont include the flag it doesnt ask you anyways lol, so its pointless, and I could never get it to ask to create the folder or not. Also, it moves/copies folders, so if you wanted to move all the files in one folder to another, you couldnt because inside the destination it would create/move another folder hence creating a sub folder, so wouldnt work if you just wanted files in there.
  • [b][red]This message was edited by dwccgc at 2004-8-12 8:7:24[/red][/b][hr]
    : well, I like it better, certainly gives me less problems, and some of the flags dont even work well, like theres a flag to make it not ask you to create a directory if it doesnt exists, to just go ahead and do it, but if you dont include the flag it doesnt ask you anyways lol, so its pointless, and I could never get it to ask to create the folder or not. Also, it moves/copies folders, so if you wanted to move all the files in one folder to another, you couldnt because inside the destination it would create/move another folder hence creating a sub folder, so wouldnt work if you just wanted files in there.
    :

    [blue]
    You have demonstated in your previous posts that you have not grasped the concept of c/c++. Just because you do not know how to use a routine, it does not make it faulty.

    The code segment here will prompt the user to create the directory ABCDEFG before copying the file win.ini.
    [code]
    SHFILEOPSTRUCT FileOp;
    memset(&FileOp, NULL, sizeof(SHFILEOPSTRUCT));

    char chFile1[_MAX_PATH] = "C:\WINDOWS\WIN.INI";
    char chFile2[_MAX_PATH] = "C:\ABCDEFG\WIN.INI";

    FileOp.wFunc = FO_COPY;
    FileOp.pFrom = chFile1;
    FileOp.pTo = chFile2;
    FileOp.fFlags = 0;
    INT nShError = SHFileOperation(&FileOp);
    [/code]

    The code segment here will [b]not[/b] prompt the user to create the directory ABCDEFG before copying the file win.ini.
    [code]
    SHFILEOPSTRUCT FileOp;
    memset(&FileOp, NULL, sizeof(SHFILEOPSTRUCT));

    char chFile1[_MAX_PATH] = "C:\WINDOWS\WIN.INI";
    char chFile2[_MAX_PATH] = "C:\ABCDEFG\WIN.INI";

    FileOp.wFunc = FO_COPY;
    FileOp.pFrom = chFile1;
    FileOp.pTo = chFile2;
    FileOp.fFlags = [b]FOF_NOCONFIRMMKDIR[/b];
    INT nShError = SHFileOperation(&FileOp);
    [/code]

    I have tested both these code segments, and they have worked according to the documentation provided by Microsoft.
    [/blue]


  • Ok thanx for all your remarks.
    I appreciate it.

    So for you all to be able to help me, lets assume that
    i am a dummy. And i only know how to apply the princeples
    of programming(which is not the case).

    I want to know how can I copy an entire folder including
    subfolders the easiest and fastest way there is.

    But please, i do not know the hardcore programming techniques.
    I am using Borland C++ 6 pro, and i need help desperate????

    So give me a step by step "manual" as to which files to include
    in my headers ext.

    Thanx again for your time.

    Greetings From Africa

    Deo Botha
    ps - i am making a backup program for myself


  • Hello for all of you
    Can you help me to solve this problem:

    I have a DBGrid in form conected to DataSource (DS is conected to the Table).
    in DBGrid I have just one field1 and I wanna make search button using EditBox to find text inside in DBGrid

    Now I can create code to search from the beging of row, but I wanna make a search code that can find text in any position of the row.

    For example:
    In row I have text: I AM A SOLDIER

    when I write in EditBox AM and click Button I wanna it find that row with rowselector

    I am using Borland builder 6

    tHank you

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories