ASL
|
This class allows enumerating the contents of a directory: its files and subdirectories.
This example lists the files of the c:/windows directory modified in the last 10 days:
In a Directory object, files()
enumerates files, subdirs()
enumerates subdirectories, and items()
enumerates both. In all three a wildcard can be given as argument to filter the search.
Each File object returned has the following members:
path()
: the full path of this itemname()
: the name of the itemdirectory()
: the full directory containing the itemsize()
: the file size in bytes (or 0 if it is a directory)lastModified()
: a Date indicating the last modification timecreationDate()
: a Date indicating the item's creation timeIn fact they are File objects and any function of that class can be used on them.
#include <Directory.h>
Public Member Functions | |
Directory (const String &name) | |
Constructs a directory from a relative or absolute path. | |
String | name () const |
Returns the name of the directory. | |
String | path () const |
Returns the full path of the directory. | |
String | directory () const |
Returns the parent directory containing this directory. | |
bool | exists () const |
Returns true if this directory exists, or false if it does not exist or refers to a file. | |
const Array< File > | items (const String &which="*", ItemType t=ALL) |
Returns the contents of a directory, optionally matching a wildcard. | |
const Array< File > | files (const String &which="*") |
Returns the files in a directory, optionally matching a wildcard. | |
const Array< File > | subdirs (const String &which="*") |
Returns the subdirectories of a directory, optionally matching a wildcard. | |
Static Public Member Functions | |
static Array< String > | roots () |
Returns a list of root paths (drives on windows, like "A:/", "C:/", or only "/" elsewhere) | |
static String | current () |
Returns the current working directory. | |
static bool | change (const String &dir) |
Sets the current working directory. | |
static bool | create (const String &name) |
Creates a new directory (and its ancestors if they don't exist), returns false on failure. | |
static bool | createOne (const String &name) |
Creates a new directory, returns false on failure (e.g if its parent does not exist) | |
static String | createTemp () |
Creates a new temporary directory with an arbitrary name and returns its path. | |
static bool | copy (const String &from, const String &to) |
Copies file from to to which can be a full name or a destination directory. | |
static bool | move (const String &from, const String &to) |
Moves or renames file from to to which can be a full name or a destination directory. | |
static bool | remove (const String &path) |
Deletes file or directory path (if it is a directory it must be empty) | |
static bool | removeRecursive (const String &path) |
Removes the given directory with all its content recursively and returns true on success (USE WITH CARE!) | |