file-split-to-directory
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

File Split To Directory

npm publish nycrc config on GitHub

split files to folders

Install

npm i -g file-split-to-directory

Notes

It may take very long time from few minutes to few hours to process all files as moving files are slow.

Make sure there is enough memory as it will required to store all filenames / path names and queue all fs.move command at onces.

Use For

Can be use for a work around for irfanview thumbnail viewer cannot load large amount of image issue

Usage

Command Line

file-split-to-directory .
file-split-to-directory "/mnt/d/download"
# each folder 4400 files (default is 4400)
file-split-to-directory "/mnt/d/download" --chunk 4400
file-split-to-directory "/mnt/d/download" -c 4400
# async may work faster over network
file-split-to-directory "/mnt/d/download" --async
file-split-to-directory "D:/Download" -c 4400 --async

Result

from

- Download
-- 1.png
-- 2.png
-- 3.png
-- ....
-- 4401.png
-- ....
-- 8801.png

to

- Download
|- 0
||- 1.png
||- 2.png
||- 3.png
||- ...
|- 1
||- 4401.png
||- ...
|- 2
||- 8801.png

Run Directly

# npm start -- <directory> --chunk [chunk=4400] --async
npm start -- "D:/download"

# with custom size
npm start -- "D:/download" --chunk 4400 --async

Api

import { FileSplitToDirectory } from 'file-split-to-directory';

(async () => {
  const fstd = new FileSplitToDirectory();
  try {
    await fstd.run('D:/download', 4400);
  } catch (e) {
    // handle file system error
  }
})();
import { FileSplitToDirectory } from 'file-split-to-directory';

try {
  new FileSplitToDirectory().runSync('D:/download');
} catch (e) {
  // handle file system error
}

Custom compare function

import { FileSplitToDirectory } from 'file-split-to-directory';

try {
  const fstd = new FileSplitToDirectory();
  // filenames will be sorted using below compare function, the default compare were as shown below
  fstd.compare = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare;

  // another example
  fstd.compare = (x: string, y: string) => Math.random();

  fstd.runSync('D:/download', 100);
} catch (e) {
  // handle file system error
}

Custom directory name generator

import { FileSplitToDirectory } from 'file-split-to-directory';

try {
  const fstd = new FileSplitToDirectory();
  // default as below
  fstd.directoryNameGenerator = (i: number) => i.toString();
  fstd.runSync('D:/download', 100);
} catch (e) {
  // handle file system error
}

Custom output directory

import { FileSplitToDirectory } from 'file-split-to-directory';

try {
  const fstd = new FileSplitToDirectory();
  fstd.runSync('D:/download', 100, 'E:/processed');
} catch (e) {
  // handle file system error
}

Package Sidebar

Install

npm i file-split-to-directory

Weekly Downloads

2

Version

2.2.0

License

MIT

Unpacked Size

74 kB

Total Files

21

Last publish

Collaborators

  • icelavender