Skip to content

Instantly share code, notes, and snippets.

@itzarty
Last active July 28, 2022 18:17
Show Gist options
  • Select an option

  • Save itzarty/cafebc08176f372e4201cff10afa68d9 to your computer and use it in GitHub Desktop.

Select an option

Save itzarty/cafebc08176f372e4201cff10afa68d9 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const watchRename = ( path, callback ) => {
let names = [ ];
fs.watch( path, ( event, filename ) => {
if( event == "rename" ) {
names.push( filename );
if( names.length > 1 ) {
if( names[ 0 ] != names[ 1 ] ) callback( names[ 0 ], names[ 1 ] );
names = [ ];
}
}
});
}
watchRename( "./", ( from, to ) => {
console.log( "File " + from + " got renamed to " + to );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment