The imagine.path
module (ImaginePath for AMS) provides you with functions for working with paths. This library can be used to construct and parse file and directory paths, get metadata about them and enumerate entries in a directory. It is based on the built in PathBuf features of Rust.
Using this module you can safely construct paths from nothing, from other paths or from individual segments. The internal functionality of this module will make sure the paths are correct when converted back to a string.
One can also extract information about existing paths, replace filenames, replace extensions, extract prefixes and inspect ancestors. Functionality for canonicalizing paths is also included, resolving path names to an absolute and correct path on the filesystem. This step ensures an entry exists and yields a standard absolute path.
Obtaining metadata about a path is important to see if one can read the entry, inspect the created, modified and accessed times, obtain the length of a file and test what type of entry this is. This functionality is included.
local path = require "imagine.path"; -- no need for this if you use the ImaginePath AMS Plugin
local dir = path.new("C:/Users/JohnDoe/Documents");
local nexter, iterator = dir:read_dir();
if (not nexter) then
-- now iterator is an error message
print("error creating the iterator: " .. iterator);
return;
end
for _, path, err in nexter, iterator do
if (err) then
print(err);
return;
end
print(path);
end