Program that modifies directories

This is a discussion on Program that modifies directories within the C++ Programming forums, part of the General Programming Boards category; I am new to C++ and would like to know how to write a program that will modify directories and/or ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    16

    Program that modifies directories

    I am new to C++ and would like to know how to write a program that will modify directories and/or files, like DOS does. If you could, it would be of great help to actually instant message me and help me step by step but if you cannot it would be nice to just post something helpful.

    (Don't bother flaming because I really do not care about your worthless opinion that will not affect my life in any way, shape or form. Thank you.)
    Signed,
    Next Gen

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    22
    You can build a function to have control in your program the way you can control a computer from the DOS prompt. Here is a simple example... Just be sure to add the header stdlib.h

    void doDOS(char *command)
    {
    system(command);
    }

    then you can call it in your program like so......

    doDOS(" ");

    In the quotes" " type a command such as.....

    doDOS("FORMAT A:"); for example... or

    doDOS("CLS"); clear screen... or even

    doDOS("MOVE C:\........ and so on.. Hope this helps

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    22
    PS: If this is what you needed help with and can't figure it out just send me a message and I will help you out.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    I am trying to get it to work right now. I get the following.

    --------------------Configuration: mike1 - Win32 Debug--------------------
    Compiling...
    mike2.cpp
    C:\mikeprogs\mike1\mike2.cpp(3) : warning C4518: 'void ' : storage-class or type specifier(s) unexpected here; ignored
    C:\mikeprogs\mike1\mike2.cpp(3) : error C2146: syntax error : missing ';' before identifier 'doDOS'
    C:\mikeprogs\mike1\mike2.cpp(3) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    mike1.exe - 2 error(s), 1 warning(s)

    The code is

    Code:
    #include <stdlib.h>
    int main()
    void doDOS(char *command)
    {
    system(command);
    ;}
    
    ;doDOS("FORMAT A:");
    ;}
    Any help would be greatly appreciated, thanks.
    Last edited by NeXtGeN; 06-23-2003 at 03:23 AM.
    Signed,
    Next Gen

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    22
    >>>>>>>>>
    #include <stdlib.h>
    int main()
    void doDOS(char *command)
    {
    system(command);
    ;}

    ;doDOS("FORMAT A:");
    ;}
    >>>>>>>>>

    You have a few errors... For one, you didn't include your standard I/O file for input/output.. before stdlib.h add this header-> iostream.h

    You cant declare the function doDOS inside of main.. it must go outside main and you call it in main using the function name doDOS()... Also, in doDOS there is no need for a semi colon before the ending brace...

    Next you need a brace pair for your function main { } The braces tell the compiler what is part of mains function body... and again no semi-colon before the call to the function doDOS or before mains ending brace... And before the last ending brace add the line... return 0;... here, try this....

    #include <iostream.h>
    #include <stdlib.h>

    void doDOS(char *command)
    {
    system(command);
    }

    int main( )
    {
    doDOS("FORMAT A:");
    return 0;
    }

    be sure to take out any disks in drive A :-)

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    Thanks again. =)
    Signed,
    Next Gen

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    I typed in EXACTLY what you told me to and got this (whew this is quite the trial and error, sorry I'm so dumb)

    --------------------Configuration: mike1 - Win32 Debug--------------------
    Linking...
    LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/mike1.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    mike1.exe - 2 error(s), 0 warning(s)
    Signed,
    Next Gen

  8. #8
    Registered User
    Join Date
    Jun 2003
    Posts
    22
    Please post exaclty what you wrote in your source code.

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    Ok.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    void doDOS(char *command)
    {
    system(command);
    }
    
    int main( )
    {
    doDOS("FORMAT A:");
    return 0;
    }
    Signed,
    Next Gen

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    22
    The code is correct and should compile fine. stdlib.h is last time I heard part of the standard library so your compiler should support this. I know this question may seem simple but since you said you just started programming I want to make sure.. When you saved your source code before compiling did you give the name the ext .cpp? As in filename.cpp.... then compiled it to make the exe? what compiler are you using?

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    It compiles fine. I get the 2 errors when building it and attempting to execute it.

    The compiler I am using is Microsoft Visual C++.
    Signed,
    Next Gen

  12. #12
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You are compiling it as a Windows GUI program not a Windows Console App. GUI programs use winmain() in place of main().

    *** EDIT ***

    What do you actually want to do? system() is a bodge at best, there is always a better way to do things.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  13. #13
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    Ok, I got it to work.
    But in terms of commands how exactly would you make a delete directory command?

    I tryed
    "DEL C:\...."
    but it didn't work.

    What should I type?
    Signed,
    Next Gen

  14. #14
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I would use the RemoveDirectory() API function.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  15. #15
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    Not recognized as a command.
    Signed,
    Next Gen

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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