Skip to content

Instantly share code, notes, and snippets.

@senthilmpro
Last active January 24, 2020 01:54
Show Gist options
  • Save senthilmpro/54717f5b6653674a5318d785e7ec4fdc to your computer and use it in GitHub Desktop.
Save senthilmpro/54717f5b6653674a5318d785e7ec4fdc to your computer and use it in GitHub Desktop.
create-folder.js
const fs = require('fs');
const path = require('path');
const HOME_PATH = "/Users/senthilmpro/Desktop/test";
const HOME_FOLDER = path.resolve(HOME_PATH);
const files = fs.readdirSync(HOME_FOLDER, 'utf-8');
console.log(files);
const isMatch = (str) => {
let str1 = str.replace("."," ")
let regEx1 = new RegExp(/\w+ \(\d+\)/,"gi");
let matches = str.match(regEx1);
if(matches && matches.length > 0){
return matches[0];
}
return null;
}
const createFolder = (str) => {
if(!fs.existsSync(str)){
fs.mkdirSync(str);
}
}
console.log("HOME_FOLDER ", HOME_FOLDER);
files.forEach(v => {
const folderName = isMatch(v);
if(folderName){
const fullPath = path.resolve(HOME_FOLDER, folderName);
console.log(fullPath);
createFolder(fullPath);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment