Last active
February 5, 2016 11:25
-
-
Save leotm/6b2354bc7d7a7441602a to your computer and use it in GitHub Desktop.
Node.js - IPVanish - OpenVPN - Sort .ovpn config files into folders by Country
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
// This will sort all IPVanish config/.ovpn files (e.g. ipvanish-BE-Brussels-bru-b01.ovpn) | |
// into respective folders (e.g. ipvanish-BE) | |
var glob = require('glob'); | |
var fs = require('fs'); | |
glob('*.ovpn', function(err, files) { | |
if (err) { throw err; } | |
files.forEach(function(item, index, array) { | |
// Create the folders | |
if (!fs.existsSync(item.substr(0, 11))) { | |
var folder = fs.mkdirSync(item.substr(0, 11)); | |
// Copy authentication file if used | |
if (fs.existsSync('login.conf')) { | |
fs.createReadStream('login.conf').pipe(fs.createWriteStream(folder + '/login.conf')); | |
} | |
} | |
// Move files to folders | |
fs.renameSync(__dirname + '\\' + item, __dirname + '\\' + item.substr(0, 11) + '\\' + item); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment