Folder
objects represent a folder on the file system, whether it exists or not, based on its path.
Folder
objects, you can:
root
/home
/here
or scriptFolder
globals
Folder()
/Item()
globals with an absolute path
folder()
on another Folder
cli
method, using the Folder
type definition
To check if a given Item
object is a Folder
, you can use the instanceof
operator.
Folder
Folder(String absolutePath)
Folder
instance for absolutePath.absolutePath |
The absolute path to the folder to get.
|
const fonts = Folder('/System/Library/Fonts/');
const directXLog = File('C:/Windows/DirectX.log');
exists
Boolean
false
.
let newFile = here.file('new-file.txt');
cli.tell(newFile.exists); // `false`
newFile.make();
cli.tell(newFile.exists); // now `true`
self
make([Boolean forgiving])
path
.forgiving |
If true:
Defaults to
false .
|
let newFile = here.file('new-file.txt');
newFile.make();
cli.tell(newFile.exists); // now `true`
let packageFolder = here.folder('new-package/');
let packageMetadata = here.file('new-package/package.json');
cli.tell(packageFolder.exists); // `false`
cli.tell(packageMetadata.exists); // `false`
packageMetadata.make(true);
cli.tell(packageFolder.exists); // `true`
cli.tell(packageMetadata.exists); // `true`
Folder
copyTo(Folder destination, [Boolean forgiving])
Folder
object representing the copy.destination |
The folder in which to create the copy.
|
forgiving |
If true, if destination doesn't exist,
Defaults to copyTo() doesn't throw and creates destination and any missing parent folder.false .
|
const playerSheetTemplate = here.file('templates/player-sheet.template.md');
let newPlayerSheet = playerSheetTemplate.copyTo(here);
newPlayerSheet.name = 'player-sheet.md';
Folder
duplicate([String newName])
Folder
object representing the copy. The name of the copy is derived from the folder's name.newName |
The name to use for the copy instead of an automatically-picked one.
duplicate() will throw if the name is taken. |
const playerSheetTemplate = here.file('templates/player-sheet.template.md');
let newPlayerSheet = playerSheetTemplate.duplicate('player-sheet.md');
newPlayerSheet.moveTo(here);
self
delete([Boolean immediately])
immediately |
If true, the folder is deleted right away instead of being placed in the trash.
Defaults to false .
|
const keepLog = await cli.ask('Keep log file?', Boolean);
if (!keepLog) here.file('events.log').delete();
Boolean
equals(Item other)
other |
The item to compare with.
|
const sourceFolder = await cli.ask('From?', Folder);
const destinationFolder = await cli.ask('To?', [Folder, function(value) {
if (value.equals(sourceFolder)) {
throw 'is the same as the source';
}
return value;
}
]);
cli.tell('Will copy from: ' + sourceFolder.name);
cli.tell('Will copy to: ' + destinationFolder.name);
name
String
const someLog = logFolder.children[0];
cli.tell(someLog.name); // "events.log"
bareName
String
const readme = here.file('README.md');
cli.tell(readme.bareName); // "README"
const minifiedMomentFile = here.file('moment.min.js');
cli.tell(minifiedMomentFile.bareName); // "moment.min"
const readme = here.file('README.md');
readme.bareName = 'First steps';
cli.tell(readme.name); // "First steps.md"
extension
String
"txt"
.path
String
cli.tell(home.path); // something like "/Users/cykelero/"
parent
Folder
const userFolderParent = home.parent;
cli.tell(userFolderParent.path);
self
moveTo(Folder destination, [Boolean forgiving])
destination |
The new parent folder.
|
forgiving |
If true, if destination doesn't exist,
Defaults to moveTo() doesn't throw and creates destination and any missing parent folder.false .
|
const folderA = here.folder('A/');
const folderB = here.folder('B/');
let file = folderA.file('file.txt');
cli.tell(file.parent.name); // "A"
file.moveTo(folderB);
cli.tell(file.parent.name); // "B"
dateCreated
Moment
dateModified
Moment
user
ItemUserPermissions
ItemUserPermissions
object for the folder. Allows reading and modifying the owner of the folder, and the owner's permissions to the folder.
const script = here.file('script.js');
script.user.canExecute = true;
group
ItemGroupPermissions
ItemGroupPermissions
object for the folder. Allows reading and modifying the owner group of the folder, and the group's permissions to the folder.
const script = here.file('script.js');
script.group.canWrite = true;
other
ItemOtherPermissions
ItemOtherPermissions
object for the folder. Allows reading and modifying world permissions to the folder.
const script = here.file('script.js');
script.other.canRead = true;
File
file(String relativePath)
relativePath |
The path to the file to get, relative to the path of the folder instance.
|
const bashProfile = home.file('.bash_profile'); // returns the .bash_profile file from the user's home folder
const hosts = root.file('etc/hosts'); // returns the /etc/hosts file
Folder
folder(String relativePath)
Folder
instance for relativePath.relativePath |
The path to the folder to get, relative to the path of the folder instance.
|
const documents = home.folder('Documents/'); // returns the Documents folder from the user's home folder
const preferences = home.folder('Library/Preferences/'); // returns the ~/Library/Preferences folder
children
Item[]
File
and Folder
objects.
const buildFolder = here.folder('build/');
buildFolder.children
.filter(child => child.extension !== 'js')
.forEach(child => child.delete());
Item[]
glob(String pattern, [Object options])
pattern |
The glob pattern.
|
options |
The options to pass to
glob . See the glob documentation for a list of supported options.
|
const buildFolder = here.folder('build/');
buildFolder.glob('*.js').forEach(child => child.delete());
size
Number
self
empty([Boolean immediately])
immediately |
If true, the children are deleted right away instead of being placed in the trash.
Defaults to false .
|
here.folder('build/').empty();
self
set(Object values)
key
-value
couple in values, sets the key
attribute of the Folder
to value
. This makes it easy to set multiple attributes on the object at once.values |
A map of property names and values.
|
let screenshotFolder = here.folder('screenshots/');
screenshotFolder.set({
name: 'screenshots-previous',
parent: here.folder('archive/')
});
return screenshotFolder.name; // returns `'screenshots-previous'`