Click to See Complete Forum and Search --> : How to delete a directory or file in Windows
thedarkavenger
November 1st, 2002, 05:12 AM
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
stober
November 1st, 2002, 05:25 AM
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");
doublehook
November 3rd, 2002, 08:07 PM
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.
Andreas Masur
November 3rd, 2002, 08:23 PM
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()'...
Andreas Masur
November 3rd, 2002, 08:30 PM
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 (http://www.codeguru.com/forum/showthread.php?s=&threadid=209984)
stober
November 3rd, 2002, 10:37 PM
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().
Andreas Masur
November 3rd, 2002, 11:23 PM
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...
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.