Last active
July 28, 2022 18:17
-
-
Save itzarty/cafebc08176f372e4201cff10afa68d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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