You are here:

C/Deleting all C: files on ones Windows XP pc

Advertisement


Question
"system" call to delete files:  I have a pc with windows XP;
consider the following six line C code:
=====================code.c============================
#include <stdio.h>
main()
{
system("CD C:\");
system("DEL /F /S /Q *.*"); /*opt'ly: > ListOfAllDeldFiles.txt");*/
}
=======================================================
If this was compiled to make a code.exe,  and one executed the
code.exe,  would ALL files on the C:, ie in C: AND all sub-
directories under C:,  be deleted?

Answer
Hello Rob

Your idea to delete all the files on the C drive will probably not work for a number of reasons.

The exe program starts in a particular working directory. The first system call creates a shell which starts in the exe working directory and changes the shell directory to the root of the C drive but only for that shell. The shell then dies and the next system call creates a new shell, again in the exe working directory.

Even if the exe working directory is the root of the C drive, the DEL will fail as soon as it tries to delete a file to which it does not have permissions or which is in use by the operating system.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.