|
-
November 1st, 2002, 06:12 AM
#1
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
-
November 1st, 2002, 06:25 AM
#2
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");
-
November 3rd, 2002, 09:07 PM
#3
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.
-
November 3rd, 2002, 09:23 PM
#4
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()'...
-
November 3rd, 2002, 09:30 PM
#5
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
-
November 3rd, 2002, 11:37 PM
#6
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().
-
November 4th, 2002, 12:23 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|