Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cluster-files

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cluster-files - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

132

bin/cluster.js
//#!/usr/bin/env node
(function () {
(function() {

@@ -8,2 +8,3 @@ 'use strict';

moment = require('moment'),
inquirer = require('inquirer'),
pt = require('path');

@@ -17,77 +18,90 @@

if (!fs.existsSync(base)) {
console.error('Folder ' + base + ' does not exists');
console.error('Folder ' + base + ' does not exists');
return;
}
//add base folder to queue
folders.push(base);
// ask the user to contiune
inquirer.prompt([{
type: "list",
name: "process",
message: "Process with folder '" + base + "' ?",
choices: ['yes', 'no']
}], function(answers) {
console.log(JSON.stringify(answers, null, " "));
//process folders
function read (folder) {
var hash = {};
if (fs.existsSync(folder)) {
if (answers.process !== 'yes') return;
var content = fs.readdirSync(folder);
//add base folder to queue
folders.push(base);
content.forEach(function (file) {
var path = pt.join(folder, file),
stats = fs.statSync(path);
if (stats.isDirectory()) {
//add to folder queue
//folders.push(path);
} else {
//add to files queue
files[path] = true;
}
});
//process folders
function read(folder) {
var hash = {};
if (fs.existsSync(folder)) {
var content = fs.readdirSync(folder);
content.forEach(function(file) {
var path = pt.join(folder, file),
stats = fs.statSync(path);
if (stats.isDirectory()) {
//add to folder queue
//folders.push(path);
} else {
//add to files queue
files[path] = true;
}
});
}
}
}
// traverse subfolders
var i = 0;
while (folders[i]) {
var folder = folders[i];
read(folder);
i++;
}
// traverse subfolders
var i = 0;
while (folders[i]) {
var folder = folders[i];
read(folder);
i++;
}
function extension (file) {
var list = file.split('.');
return list[list.length-1];
}
function extension(file) {
var list = file.split('.');
return list[list.length - 1];
}
//move files to base folder
Object.keys(files).forEach(function (key) {
var path = key,
file = pt.basename(path),
counter = 1;
//move files to base folder
Object.keys(files).forEach(function(key) {
var path = key,
file = pt.basename(path),
counter = 1;
var stats = fs.statSync(key),
subdir = stats.mtime.toISOString().substr(0,7),
dir = pt.join(base, subdir),
target = pt.join(dir, file),
time = moment(stats.mtime);
var stats = fs.statSync(key),
subdir = stats.mtime.toISOString().substr(0, 7),
dir = pt.join(base, subdir),
target = pt.join(dir, file),
time = moment(stats.mtime);
var name = time.format('YYYY-MM-DD_HH-mm-ss') + '.' + extension(file);
target = pt.join(dir, name);
// add one second to filenames time part until no file will be overwritten
while (fs.existsSync(target)) {
time = time.add('s', 1);
name = time.format('YYYY-MM-DD_HH-mm-ss') + '.' + extension(file);
var name = time.format('YYYY-MM-DD_HH-mm-ss') + '.' + extension(file);
target = pt.join(dir, name);
}
//create subdir
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
// add one second to filenames time part until no file will be overwritten
while (fs.existsSync(target)) {
time = time.add('s', 1);
name = time.format('YYYY-MM-DD_HH-mm-ss') + '.' + extension(file);
target = pt.join(dir, name);
}
//rename/move
if (!fs.existsSync(target)) {
fs.renameSync(path, target);
delete files[key];
}
//create subdir
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
//rename/move
if (!fs.existsSync(target)) {
fs.renameSync(path, target);
delete files[key];
}
});
});
}());
{
"name": "cluster-files",
"version": "0.1.0",
"version": "0.1.1",
"description": "CLI that rename files of a directory based on the creation date and clusters them in monthly based subdirectories",

@@ -10,2 +10,3 @@ "main": "lib/buckets",

"dependencies": {
"inquirer": "^0.9.0",
"moment": "~2.10"

@@ -36,2 +37,1 @@ },

}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc