Example: system
This example, for the Windows platform, creates a new directory, xyz, and a new file under it, short_lifespan.txt.
The system function executes a dir command. The output of the command is written (using `>') to the newly created file. The content of the file should be a list of the contents of the C drive.
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); else lr_output_message ("Created new directory %s", new_dir);
sprintf(filename, "%s\\%s", new_dir, "newfile.txt");
// Execute a dir /b command and direct it to a new file
sprintf(command, "dir /b c:\\ > %s /w", filename); system(command); lr_output_message ("Created new file %s", filename);
Example: output:
Action.c(10): Created new directory C:\xyz
Action.c(17): Created new file C:\xyz\newfile.txt