Created
January 29, 2020 03:29
-
-
Save senthilmpro/c9361510450211cb5bc4f4422995469d to your computer and use it in GitHub Desktop.
create-folder-2.js
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
const fs = require('fs'); | |
const path = require('path'); | |
// settings. | |
const CONF = { | |
HOME_PATH : "/Volumes/SYMC/movies/2-hindi/2-hindi-hevc" | |
} | |
const createFolder = (str) => { | |
if(!fs.existsSync(str)){ | |
fs.mkdirSync(str); | |
} | |
} | |
const HOME_PATH = CONF.HOME_PATH; | |
const HOME_FOLDER = path.resolve(HOME_PATH); | |
const files = fs.readdirSync(HOME_FOLDER, 'utf-8'); | |
console.log(files); | |
const isMatch = (str) => { | |
let matchFound = false; | |
let result; | |
let str1 = str.replace(/\./gi,' '); | |
let regEx1 = new RegExp(/[\w+ ]+\(\d+\)/,"gi"); | |
let matches = str1.match(regEx1); | |
if(matches && matches.length > 0){ | |
matchFound = true; | |
result = matches[0]; | |
} | |
let regEx2 = new RegExp(/[\w(')+ ]+ (19[5-9]\d|20[0-4]\d|2050)+/); | |
let matches2 = str1.match(regEx2); | |
if(matches2 && matches2.length > 0){ | |
matchFound = true; | |
result = matches2; | |
} | |
return result; | |
} | |
console.log("HOME_FOLDER ", HOME_FOLDER); | |
let isCreateFolder = true; | |
files.forEach(v => { | |
const arr = isMatch(v); | |
if(arr && arr.length > 0){ | |
var year = arr[1]; | |
var fname = arr[0]; | |
fname = fname.replace(year, "("+year+")"); | |
var folderName = fname; | |
console.log(folderName); | |
if(folderName && isCreateFolder){ | |
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