greenhouse
a creative coding toolkit for spatial interfaces

File Handling

Convenience methods for finding files and directories on disk.

  • FindFilePath ()
  • FindDirPath ()
  • FileExists ()
  • StrToFile ()
  • StrFromFile ()

Example

#include "Greenhouse.h"

void Setup ()
{ Str image_folder = FindDirPath ("images");
  if (image_folder . IsEmpty ())
    { INFORM ("Oh Noes! Where is the images folder?");
      return;
    }
  INFORM ("The images folder lives here: " + image_folder);

  Str img_path = "images/1.jpg";
  if (FileExists (img_path))
    INFORM ("Found " +  img_path + " in the working directory");
  else
    INFORM (img_path + " was not found in the working directory");

  Str full_img_path = FindFilePath (img_path);
  if (full_img_path . IsEmpty ())
    { INFORM (img_path + " is nowhere to be found");
      return;
    }
  INFORM ("Found " + img_path + " here: " + full_img_path);

  // NOTE: Image uses FindFilePath for its path lookup, so the above
  //       logic is unecessary for this example except for showing usage
  Image *im = new Image (full_img_path);
  im -> SlapOnFeld();

  // Save the path string to file and read it back in
  if (StrToFile (full_img_path, "temp.txt"))
    INFORM ("Path was " + StrFromFile ("temp.txt"));
}