Skip to content

Instantly share code, notes, and snippets.

@leotm
Last active February 5, 2016 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leotm/6b2354bc7d7a7441602a to your computer and use it in GitHub Desktop.
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 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