# find-file-in-folders

> Try to find a file in given folders

Latest version **1.0.3** (published 2020-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install find-file-in-folders
pnpm add find-file-in-folders
yarn add find-file-in-folders
bun add find-file-in-folders
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-06-24 |
| First published | 2020-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Zoltan David |
| Maintainers | davidzoltan828 |
| Keywords | find, file, filesystem, include |

## Links

- npm: https://www.npmjs.com/package/find-file-in-folders
- Repository: https://github.com/davidzoli/find-file-in-folders
- Issues: https://github.com/davidzoli/find-file-in-folders/issues
- npm.io page: https://npm.io/package/find-file-in-folders

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-06-24
- 1.0.2 — 2020-06-23
- 1.0.1 — 2020-06-23
- 1.0.0 — 2020-06-23

## README

# find-file-in-folders

> Try to find a file in the given folder(s).
> File can have a leading undescore.
> Inspired by SASS @import syntax.

## Parameters

**File name**

File to include. It can contain subfolder segment(s) and extension.

**Default extension**

Default extension can be set for easier file name redirection to the function. 
See wrapper function example.  
If the file name contains extension, set this false. 

**Folders array**

Array of the folders where the file possibly can be found.

## Usage

```js
const findFile = require('find-file-in-folders');
const folders = ['jsFiles', 'txtFiles', 'htmlFiles'];

let filePath = findFile('hello', '.txt', folders);
console.log(filePath);
//=> 'txtFiles\hello.txt';

filePath = findFile('hello.txt', false, folders);
console.log(filePath);
//=> 'txtFiles\hello.txt';

filePath = findFile('partials/head', '.html', folders);
console.log(filePath);
//=> 'htmlFiles\partials\_head.html';

filePath = findFile('partials/head', '.txt', folders);
console.log(filePath);
//=> 'Unable to find filepath "partials/head";
//=> false;
```

Advised to use it in a wrapper function which using files.
```js

const findFile = require('find-file-in-folders');
const fs = require('fs');
const folders = [
    'src/html/components/',
    'src/html/modules/',
    'src/html/sections/',
];

const readFile = filePath => {
  const fpath = findFile(filePath, '.html', folders);
  if (fpath !== false) {
    return fs.readFileSync(fpath, 'utf-8');
  }
  return '';
}

// want to read src/html/modules/_head.html
console.log(readFile('head'));
//=> contents of src/html/modules/_head.html file
```
For more examples check the tests.js file.

## About


### Running tests

Install dependencies and run tests with the following command:

```sh
$ npm install && npm test test.js
```

### Author

**Zoltan David**

* [github/davidzoli](https://github.com/davidzoli)

### License

Copyright © 2020, [Zoltan David](https://github.com/davidzoli).
Released under the [MIT License](LICENSE).

---
_Source: https://npm.io/package/find-file-in-folders · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
