Code Monkey home page Code Monkey logo

webdirlist's Introduction

Webdirlistnpm version

webdirlist is a versatile library designed to list files in a directory. It can be used in both Node.js and browser environments. In static hosting scenarios, it prepares a comprehensive listing of all files within a directory in a files.txt file.

Features

  • Tracedir Command: Generate a files.txt file containing information about all files in a specified directory.
  • getFileList Function: Retrieve a list of files from files.txt or directly from the file system in Node.js.

Installation

Install the package using npm:

npm install webdirlist -g

then

tracedir <blank for current fodler, or input the fodler path>

CDN Install

Via jsDelivr:

<script src="https://cdn.jsdelivr.net/npm/webdirlist/dist/webdirlist.js"></script>
or
<script type="module">
    import webdirlist from 'https://cdn.jsdelivr.net/npm/webdirlist/dist/webdirlist.esm.js';
</script>

Usage

Generating files.txt

Run the tracedir command with npx:

npx tracedir <folder-path>

e.g.
npx tracedir .\node_modules\esbuild\

This will generate a files.txt in the specified folder.

bin/esbuild	9180	1702310819
install.js	10923	1702310819
lib/main.d.ts	21152	1702310819
lib/main.js	88340	1702310819
LICENSE.md	1069	1702310819
package.json	1260	1702310819
README.md	175	1702310819

In the Browser

import webdirlist from 'webdirlist';

//optional, set the current folder, leave blank=auto
webdirlist.getInstance().setCWD();

// Async function to get file list
webdirlist.getInstance().loadDir('node_modules/esbuild').then(async()=>{
    const files=await webdirlist.getInstance().getFileList('node_modules/esbuild/lib',{
        subfolder:true,//optional,default true
        includedExt:['json','png','mp3'],//optional
        excludedExt:['txt'],//optional
        ignoreFiles:['unuse.json'],//optional
        ignoreFolder:['temp'],//optional
    });
    // list of filenames in string array
    //['lib/main.d.ts','lib/main.js']
})

In Node.js

don't need to read files.txt in advance , just run webdirlist.getInstance().getFileList directly

Contributing

Contributions to the project are welcome. Please ensure that your code adheres to the project's coding standards and include tests for new features.

License

webdirlist is MIT licensed.

webdirlist's People

Contributors

hocti avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.