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

renamer_tool

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

renamer_tool

Rename files based on a list you provide (like a bunch of videos that you want to change all of them to a new list based on table of contents)

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

RenamerTool

Rename files based on a list you provide (like a bunch of videos that you want to change all of them to a new list based on table of contents)

  • SeyyedMahdi hassanpour
  • Seyyedkhandon@gmail.com
  • ISC license
  • Note: your new_names.txt must have new names based on the same naming order as your'e files are in the directory. then after make sure it satisfy the condition, set the correct file type
  • to run this, first "npm i", then "node renamer.js"

this is a stand-alone package which you can download and use it.

const fs = require("fs");
const glob = require("glob");
const Rx = require("rxjs");
const { map, mergeMap } = require("rxjs/operators");
const readFileAsObservable$ = Rx.bindNodeCallback(fs.readFile);
const listDirectoryAsObservable$ = Rx.bindNodeCallback(glob);
const renameFileAsObservable$ = Rx.bindNodeCallback(fs.rename);
// list of new names and type of files
const newNamesFile = "new_names.txt";
const fileType = "PNG";
// methods
const splitTextToNames = (text) => text.split("\r\n");
const nameGenerator = (name, index) => `${index}_${name}.${fileType}`;
const observer = {
  next: (_) => console.log(`${_.old_name} --> ${_.new_name}`),
  error: (err) => console.log(err),
  complete: () => console.log("Finished."),
};
//observables
const newNames$ = readFileAsObservable$(newNamesFile, "utf8").pipe(
  mergeMap(splitTextToNames),
  map(nameGenerator)
);
const currentFilesNames$ = listDirectoryAsObservable$(`*.${fileType}`).pipe(
  mergeMap(Rx.from)
);
const renameFile = (names_pair) => {
  const [old_name, new_name] = names_pair;
  renameFileAsObservable$(old_name, new_name).subscribe();
  return { old_name, new_name };
};

Rx.zip(currentFilesNames$, newNames$).pipe(map(renameFile)).subscribe(observer); 

Keywords

FAQs

Package last updated on 01 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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