# File

#### new File()

Source:
  - file.js, line 17

### Methods

#### (static) create()

Static factory method to create an instance of File

Source:
  - file.js, line 542

##### Returns:

File instance

##### Example

    import File from 'file-js';

    const file = File.create();

#### getAbsolutePath()

Returns the absolutePath

Source:
  - file.js, line 418

##### Returns:

String

##### Example

    import File from 'file-js';

    const file = File.create('myFile');
    console.log(file.getAbsolutePath());

#### getCanonicalPath()

Returns the canonical path

Source:
  - file.js, line 439

##### Returns:

String

##### Example

    import File from 'file-js';

    const file = File.create('myFile');
    console.log(file.getCanonicalPath());

#### getDepthSync()

Synchronously caculate the depth of a directory

Source:
  - file.js, line 379

##### Returns:

boolean

##### Example

    import File from 'file-js';

    const file = File.create('myDirectory');
    console.log(file.getDepthSync());

#### getFiles(globopt)

Get list of file objects, if pathname is a directory

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`glob` | string | <optional> | file glob

Source:
  - file.js, line 313

##### Returns:

a promise. If the Promise fulfils, the fulfilment value is a list of File objects

##### Example

    import File from 'file-js';

    // get last modified time of all json files
    const file = File.create('./myDirectory');
    file.getFiles('*.json')
    .then((jsonFiles) => {
       console.log(jsonFiles.map(file => file.lastModifiedSync()));
    });

#### getFileSync()

Synchronously get list of file objects, if pathname is a directory

Source:
  - file.js, line 350

##### Returns:

array of files

##### Example

    import File from 'file-js';

    const file = File.create('./myHiddenFile');
    const files = file.getFileSync();
    console.log(files);

#### getList(globopt)

Get list of file objects, if pathname is a directory

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`glob` | string | <optional> | file glob

Source:
  - file.js, line 284

##### Returns:

a promise. If the Promise fulfils, the fulfilment value is a list of pathnames

##### Example

    import File from 'file-js';

    // get all json files
    const file = File.create('./myDirectory');
    file.getFiles('*.json')
    .then((jsonFiles) => {
       console.log(jsonFiles);
    });

#### getListSync()

Synchronously get list of files, if pathname is a directory

Source:
  - file.js, line 260

##### Returns:

array of files

##### Example

    import File from 'file-js';

    const file = File.create('./myHiddenFile');
    const files = file.getListSync();
    console.log(files);

#### getName()

Returns the pathname as a string

Source:
  - file.js, line 400

##### Returns:

String

##### Example

    import File from 'file-js';

    const file = File.create('myDirectory');
    console.log(file.getName());

#### getPathExtension()

Returns the file extension.

Source:
  - file.js, line 457

##### Returns:

String

##### Example

    import File from 'file-js';

    const file = File.create('./tmp.sh');
    console.log(file.getPathExtension()); // sh

#### isDirectory()

Determine if pathname is a file

Source:
  - file.js, line 203

##### Returns:

If the Promise fulfils, the fulfilment value is a boolean indicating if the pathname is a file

##### Example

    import File from 'file-js';

    const file = File.create('myDirectory');
    file.isFile((isFile) => {
      console.log(isFile);
    });

#### isDirectory()

Determine if pathname is a directory

Source:
  - file.js, line 115

##### Returns:

If the Promise fulfils, the fulfilment value is a boolean indicating if the pathname is a directory

##### Example

    import File from 'file-js';

    const file = File.create('myDirectory');
    file.isDirectory((isDirectory) => {
      console.log(isDirectory);
    });

#### isDirectory()

Determine if pathname is a file

Source:
  - file.js, line 159

##### Returns:

If the Promise fulfils, the fulfilment value is a boolean indicating if the pathname is a file

##### Example

    import File from 'file-js';

    const file = File.create('myDirectory');
    file.isFile((isFile) => {
      console.log(isFile);
    });

#### isDirectorySync()

Synchronously determine if pathname is a directory

Source:
  - file.js, line 55

##### Returns:

boolean

##### Example

    import File from 'file-js';

    const file = File.create('myDirectory');
    if (file.isDirectorySync()) {
       console.log('processing directory');
    }

#### isFileSync()

Synchronously determine if pathname is a file

Source:
  - file.js, line 95

##### Returns:

boolean

##### Example

    import File from 'file-js';

    const file = File.create('myDirectory');
    if (file.isFileSync()) {
       console.log('processing file');
    }

#### isHiddenSync()

Synchronously determine if pathname is a hidden file

Source:
  - file.js, line 180

##### Returns:

boolean

##### Example

    import File from 'file-js';

    const file = File.create('./myHiddenFile');
    if (file.isHiddenSync()) {
       console.log('processing hidden file');
    }

#### isSocket()

Determine if pathname is a Socket

Source:
  - file.js, line 137

##### Returns:

If the Promise fulfils, the fulfilment value is a boolean indicating if the pathname is a Socket

##### Example

    import File from 'file-js';

    const file = File.create('mySocket');
    file.isSocket((isSocket) => {
      console.log(isSocket);
    });

#### isSocketSync()

Synchronously determine if pathname is a socket

Source:
  - file.js, line 75

##### Returns:

boolean

##### Example

    import File from 'file-js';

    const file = File.create('mysocket');
    if (file.isSocketSync()) {
       console.log('processing socket');
    }

#### rename(pathname)

Renames the abstract pathname

##### Parameters:

Name | Type | Description
--- | --- | ---
`pathname` | string | File | pathname either as a string or File instance

Source:
  - file.js, line 230

##### Returns:

If the Promise fulfils, the fulfilment value is undefined

##### Example

    import File from 'file-js';

    const original = File.create('fileA');
    const renameTo = File.create('fileB');
    original
     .rename(renameTo)
     .then(() => {
        console.log(original.getName()) // prints fileA
     });

#### withLock()

Locks the pathname

Source:
  - file.js, line 514

##### Returns:

returning value of function

##### Example

    import File from 'file-js';

    const file = File.create('myFile');
    file.with(() => {
      if (file.isFileSync()) {
        file.delete();
      }
    });