Last active
November 7, 2018 19:24
-
-
Save enriqueornelasjr/464f567a76e4b92fe7c5597e139c647a to your computer and use it in GitHub Desktop.
Cleans folder where this file is run by putting files into folders based on their extensions
This file contains 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
/* | |
-------- | |
Clean.js | |
-------- | |
Gist that cleans folder where this file is run by | |
putting files into folders based on their extensions | |
Current folders are ignored | |
Run using | |
node Clean.js | |
*/ | |
var fs = require("fs"); | |
var files = fs.readdirSync("./"); | |
var path = require("path"); | |
var fileName = path.basename(__filename); | |
for (var ind in files) { | |
var file = files[ind]; | |
var p = path.join(__dirname, file); | |
var isDir = fs.lstatSync(p).isDirectory(); | |
if (isDir || file == fileName) | |
continue; | |
var ext = file.substring(file.lastIndexOf(".") + 1); | |
ext = ext.substring(0, 1).toUpperCase() + ext.substring(1).toLowerCase(); | |
if (!fs.existsSync(ext + " Files/")) | |
fs.mkdirSync(ext + " Files/"); | |
fs.renameSync(file, ext + " Files/" + file); | |
console.log("Moved './" + file + "' into './" + ext + " Files/"+file+"'"); | |
} | |
console.log("Finished cleaning"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment