π cyfs :: Cyclone in file system. Order based file handling Node.js module.
- select
- get selected files
- report
- output a report file that contains selected files info
- delete
- delete selected files
- rename
- rename selected files (filename only)
- fetch
- copy selected files and keep the tree
- chronicle
- restructure files to timestamp-based path
- copy
- copy selected files as you like (dirname can be changed)
- move
- move selected files as you like (dirname can be changed)
$ npm install cyfs
β Node v14.13+ (CommonJS)
const cyfs = require("cyfs")
const order = {
select: {
pattern: "Photos Library.photoslibrary/Masters/**/*.mov",
options: {
cwd: "/Users/syon/Pictures",
},
},
}
const selected = await cyfs(order)
/*
Photos Library.photoslibrary/Masters/2018/02/02/20180201-120000/IMG_0022.MOV
Photos Library.photoslibrary/Masters/2018/03/03/20180301-120000/IMG_0103.MOV
Photos Library.photoslibrary/Masters/2018/04/04/20180401-120000/IMG_0144.MOV
Photos Library.photoslibrary/Masters/2018/05/05/20180501-120000/IMG_0205.MOV
Photos Library.photoslibrary/Masters/2018/06/06/20180601-120000/IMG_0360.MOV
*/
const cyfs = require("cyfs")
const order = {
select: {
pattern: "test/dataset/photos/**/*.jpg",
},
action: {
do: "report",
},
}
const result = await cyfs(order, { preview: true })
Result
[ { dir: 'test/dataset/photos',
name: 'tg2_drip.jpg',
type: 'F',
byte: 10913,
access_time: '2018-05-27T01:23',
modify_time: '2018-05-20T12:59',
change_time: '2018-05-27T01:22',
birth_time: '2018-05-20T03:30',
exif_date: '2013-01-05T11:21' },
{ dir: 'test/dataset/photos',
name: 'tg2_pink.jpg',
type: 'F',
byte: 14439,
access_time: '2018-05-27T01:23',
modify_time: '2018-05-27T01:10',
change_time: '2018-05-27T01:12',
birth_time: '2018-05-27T01:10',
exif_date: '2013-01-05T11:19' },
{ dir: 'test/dataset/photos',
name: 'tg2_red.jpg',
type: 'F',
byte: 19348,
access_time: '2018-05-27T01:23',
modify_time: '2018-05-27T01:10',
change_time: '2018-05-27T01:12',
birth_time: '2018-05-27T01:10',
exif_date: '2013-03-09T11:42' } ]
report.tsv
dir name type byte access_time modify_time change_time birth_time exif_date
test/dataset/photos tg2_drip.jpg F 10913 2018-05-27T01:23 2018-05-20T12:59 2018-05-27T01:22 2018-05-20T03:30 2013-01-05T11:21
test/dataset/photos tg2_pink.jpg F 14439 2018-05-27T01:23 2018-05-27T01:10 2018-05-27T01:12 2018-05-27T01:10 2013-01-05T11:19
test/dataset/photos tg2_red.jpg F 19348 2018-05-27T01:23 2018-05-27T01:10 2018-05-27T01:12 2018-05-27T01:10 2013-03-09T11:42
const cyfs = require("cyfs")
const order = {
select: {
pattern: "**/*.log",
name: {
regex: {
pattern: "^may-20..",
flags: "gi",
},
contain: ["debug", "warn", "error"],
},
size: {
min: 1000,
max: "3MB",
},
},
action: {
do: "delete",
},
}
const deleted = await cyfs(order, { preview: true })
/*
path/to/May-2018_access.debug.log
path/to/May-2018_access.warn.log
path/to/May-2018_access.error.log
*/
const order = {
select: {
pattern: "test/dataset/week/*.log",
},
action: {
do: "rename",
args: {
regex: true,
find: "^F",
replace: "PREMIUM-F",
},
},
}
const result = await cyfs(order, { preview: true })
/*
test/dataset/week/PREMIUM-Friday.log
*/
const order = {
select: {
pattern: "test/dataset/holidays/*",
},
action: {
do: "rename",
args: {
timestamp: {
format: "YYYYMMDD - ",
/* Remove original filename */
// only: true
},
},
},
}
const result = await cyfs(order, { preview: true })
/*
test/dataset/holidays/20180505 - Children\'s Day.h
test/dataset/holidays/20180504 - Greenery Day.h
test/dataset/holidays/20180716 - Marine Day.h
test/dataset/holidays/20180811 - Mountain Day.h
*/
const cyfs = require("cyfs")
const order = {
select: {
pattern: "Photos Library.photoslibrary/Masters/2018/**/*.mov",
options: {
cwd: "/Users/syon/Pictures",
},
},
action: {
do: "fetch",
args: {
baseDir: "Photos Library.photoslibrary/Masters/2018",
destDir: "2018-movies",
},
},
}
const fetched = await cyfs(order)
/*
2018-movies/02/02/20180201-120000/IMG_0022.MOV
2018-movies/03/03/20180301-120000/IMG_0103.MOV
2018-movies/04/04/20180401-120000/IMG_0144.MOV
2018-movies/05/05/20180501-120000/IMG_0205.MOV
2018-movies/06/06/20180601-120000/IMG_0360.MOV
*/
const cyfs = require("cyfs")
const order = {
select: {
pattern: "Photos Library.photoslibrary/Masters/2018/**/*.mov",
options: {
cwd: "/Users/syon/Pictures",
},
},
action: {
do: "chronicle",
args: {
preferExif: true,
baseDir: "Photos Library.photoslibrary/Masters/2018",
destDir: "2018-movies",
// https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
destFormat: "YYYY/MM/DD",
},
},
}
const fetched = await cyfs(order)
/*
2018-movies/2018/02/01/IMG_0022.MOV
2018-movies/2018/03/01/IMG_0103.MOV
2018-movies/2018/04/01/IMG_0144.MOV
2018-movies/2018/05/01/IMG_0205.MOV
2018-movies/2018/06/01/IMG_0360.MOV
*/
const cyfs = require("cyfs")
const order = {
select: {
pattern: "test/dataset/colors/*",
},
action: {
do: "copy", // "move"
args: {
find: "dataset/colors/(.*).txt",
replace: "market/$1-ocean.txt",
},
},
}
const result = await cyfs(order, { preview: true })
/*
test/market/blue-ocean.txt
test/market/green-ocean.txt
test/market/red-ocean.txt
*/
select:
pattern: "path/of/glob/**"
options:
cwd: "/Users/syon/Pictures"
dot: true
nodir: true
nocase: true
include:
name:
regex:
pattern: "(JPG|PNG)$"
flags: gi
contain:
- IMG
- DSC
size:
min: 1000,
max: "5MB",
date:
mode: modify
after: 2000-01-01
before: 2000-12-31
datetime:
mode: modify
after: "2000-01-01 00:00:00.000"
before: "2000-12-31 23:59:59.999"
action:
do: select|delete|rename|fetch|chronicle|copy|move
args: <object>
https://github.com/isaacs/node-glob#glob-primer
https://github.com/isaacs/node-glob#options
- (default)
- nodir:
true
- nocase:
true
- nodir:
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
- mode:
exif
|access
|modify
|change
|birth
- after
YYYY-MM-DD
- before
YYYY-MM-DD
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
- mode:
exif
|access
|modify
|change
|birth
- after
YYYY-MM-DD HH:mm:ss.SSS
- before
YYYY-MM-DD HH:mm:ss.SSS