Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File Deletion

Posted on 1998-05-17
3
Medium Priority
?
184 Views
Last Modified: 2010-04-10
How would you delete a file or folder?  Also, how would you check if the file or folder exists in the indicated
drive?
0
Comment
Question by:strider031598
  • 3
3 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 120 total points
ID: 1162311
I can give you  two answers:  one Win32 specific and one that uses the C standard runtime library.

Answers below...
0
 
LVL 11

Expert Comment

by:alexo
ID: 1162312
The Win32 way:

DeleteFile() - deletes a file.

RemoveDirectory - deletes an empty directory.

To find if a file or directory exists, use FindFirstFile() or FindFirstFileEx().  Don't forget to terminate the search using FindClose().
Another way is to use GetFileAttributes().  The call will fail if the file does not exist.

A "standard" way described below...
0
 
LVL 11

Expert Comment

by:alexo
ID: 1162313
A correction: the access() (or _access() on some compilers) function is much better for checking file/directory existence.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question