UNPKG

3.06 kBTypeScriptView Raw
1import { Disposable } from '../../../index';
2import { File } from './file';
3
4/** Represents a directory on disk that can be watched for changes. */
5export class Directory {
6 // Construction
7 /** Configures a new Directory instance, no files are accessed. */
8 constructor(directoryPath: string, symlink?: boolean);
9
10 /**
11 * Creates the directory on disk that corresponds to ::getPath() if no such
12 * directory already exists.
13 */
14 create(mode?: number): Promise<boolean>;
15
16 // Event Subscription
17 /** Invoke the given callback when the directory's contents change. */
18 onDidChange(callback: () => void): Disposable;
19
20 // Directory Metadata
21 /** Returns a boolean, always false. */
22 isFile(): this is File;
23
24 /** Returns a boolean, always true. */
25 isDirectory(): this is Directory;
26
27 /** Returns a boolean indicating whether or not this is a symbolic link. */
28 isSymbolicLink(): boolean;
29
30 /**
31 * Returns a promise that resolves to a boolean, true if the directory
32 * exists, false otherwise.
33 */
34 exists(): Promise<boolean>;
35
36 /** Returns a boolean, true if the directory exists, false otherwise. */
37 existsSync(): boolean;
38
39 /**
40 * Return a boolean, true if this Directory is the root directory of the
41 * filesystem, or false if it isn't.
42 */
43 isRoot(): boolean;
44
45 // Managing Paths
46 /**
47 * This may include unfollowed symlinks or relative directory entries.
48 * Or it may be fully resolved, it depends on what you give it.
49 */
50 getPath(): string;
51
52 /**
53 * All relative directory entries are removed and symlinks are resolved to
54 * their final destination.
55 */
56 getRealPathSync(): string;
57
58 /** Returns the string basename of the directory. */
59 getBaseName(): string;
60
61 /** Returns the relative string path to the given path from this directory. */
62 relativize(fullPath: string): string;
63
64 // Traversing
65 /** Traverse to the parent directory. */
66 getParent(): Directory;
67
68 /**
69 * Traverse within this Directory to a child File. This method doesn't actually
70 * check to see if the File exists, it just creates the File object.
71 */
72 getFile(filename: string): File;
73
74 /**
75 * Traverse within this a Directory to a child Directory. This method doesn't actually
76 * check to see if the Directory exists, it just creates the Directory object.
77 */
78 getSubdirectory(dirname: string): Directory;
79
80 /** Reads file entries in this directory from disk synchronously. */
81 getEntriesSync(): Array<File | Directory>;
82
83 /** Reads file entries in this directory from disk asynchronously. */
84 getEntries(callback: (error: Error | null, entries: Array<File | Directory>) => void): void;
85
86 /**
87 * Determines if the given path (real or symbolic) is inside this directory. This
88 * method does not actually check if the path exists, it just checks if the path
89 * is under this directory.
90 */
91 contains(pathToCheck: string): boolean;
92}