CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2001
    Posts
    87

    please help here!!!

    Can anybody tell me about the 'system' function in C++?
    Like if i want to create a directory or create or delete a directory of the user's choice?
    The filename or directory name is stored in a string
    And i want to delete it using system("del filename");
    how do i delete the file or directory specified by the user?
    Thank You

  2. #2
    Join Date
    Jun 2002
    Posts
    1,417
    There are standard functions to crate and delete directories.
    On Microsoft Windows platforms
    To create a directory call the function CreateDirectory()
    To delete a directory: DeleteDirectory()

    Or you could use the system function call as you suggested.
    system("rmdir SomeDirectoryName");

  3. #3
    Join Date
    Sep 2002
    Posts
    28

    A way for deleting files

    You have this win32 API

    BOOL DeleteFile(
    LPCTSTR lpFileName // pointer to name of file to delete
    );

    You have a method for selecting a file:

    BOOL GetOpenFileName(
    LPOPENFILENAME lpofn // address of struct with initialization data
    );

    This creates a Open file dialog that returns the name of
    selected file. You can customize the properties of dialog
    box with the structure OPENFILENAME, i.e.: a dialog box
    with a title "SELECT FILE TO DELETE" and a filter *.* for
    all the files.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by stober
    There are standard functions to crate and delete directories.
    On Microsoft Windows platforms
    To create a directory call the function CreateDirectory()
    To delete a directory: DeleteDirectory()
    I would not consider 'DeleteDirectory()' as a standard windows function. It does not exist before .NET came out. Furthermore as far as I know it is only available in Visual Basic.

    For Visual C++ programs you would have to write your own function using a recursive approach of 'DeleteFile()'...

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: please help here!!!

    Originally posted by thedarkavenger
    Can anybody tell me about the 'system' function in C++?
    Like if i want to create a directory or create or delete a directory of the user's choice?
    The filename or directory name is stored in a string
    And i want to delete it using system("del filename");
    how do i delete the file or directory specified by the user?
    Thank You
    An example of how you could delete a complete directory including subdirectories can be found here

  6. #6
    Join Date
    Jun 2002
    Posts
    1,417
    Originally posted by Andreas Masur

    I would not consider 'DeleteDirectory()' as a standard windows function. It does not exist before .NET came out. Furthermore as far as I know it is only available in Visual Basic.

    For Visual C++ programs you would have to write your own function using a recursive approach of 'DeleteFile()'...
    You are quite right -- that should have been RemoveDirectory(), not DeleteDirectory().

  7. #7
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by stober
    You are quite right -- that should have been RemoveDirectory(), not DeleteDirectory().
    Just as an addition...'RemoveDirectory()' only deletes an empty directory...therefore you most-likely have to empty the directory first...my previous mentioned recursive approach for example...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured