-
Notifications
You must be signed in to change notification settings - Fork 0
/
duplicacy-unflatten.js
34 lines (29 loc) · 960 Bytes
/
duplicacy-unflatten.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require( 'fs' );
const mkdirp = require('mkdirp');
fs.readdir( ".", function( err, files ){
if( err ) {
console.error( "Could not list the directory.", err );
process.exit( 1 );
}
files.forEach( function( file, index ){
fs.stat( file, function( error, stat ){
if( error ) {
console.error( "Error stating file.", error );
return;
}
if( stat.isFile() ){
var first = file.substring( 0,2 );
var second = file.substring( 2,4 );
var rest = file.substring( 4,file.length );
mkdirp( "./" + first + "/" + second, function( error ) {
if( error ){
console.error( "Error creating folder.", error );
return;
} else {
fs.rename( file, "./" + first + "/" + second + "/" + rest );
}
});
}
});
});
});