Example: rmdir
This example, for the Windows platform, creates a new directory, xyz, and a new file under the directory, short_lifespan.txt. It then deletes the new file with remove and the new directory with rmdir.
extern int errno; char filename[1024], command[1024]; char new_dir[] = "C:\\xyz";
// Create a directory under root called xyz and make it the current dir
if (mkdir(new_dir)) { lr_output_message ("Create directory %s failed", new_dir); return -1; } else lr_output_message ("Created new directory %s", new_dir);
// Create a new file in the new directory, the text is the output of a dir command on the new directory
sprintf(filename, "%s\\%s", new_dir, "short_lifespan.txt"); sprintf(command, "dir %s > %s /w", new_dir, filename ); system(command); lr_output_message ("Created new file %s", filename);
// Now delete the file
if (remove(filename) == 0) lr_output_message ("Removed new file %s", filename); else lr_output_message ("Unable to remove %s error %d", filename, errno);
// Now delete the new directory
if (rmdir(new_dir) == 0) lr_output_message ("Removed new directory %s", new_dir); else lr_output_message ("Unable to remove %s error %d", new_dir, errno);
Example: Output:
Action.c(15): Created new directory C:\xyz
Action.c(22): Created new file C:\xyz\short_lifespan.txt
Action.c(26): Removed new file C:\xyz\short_lifespan.txt
Action.c(32): Removed new directory C:\xyz