I am quite new in using JS, so I will try to be as specific as I can :)
I have a folder with 260 .png files with different country names: Afghanistan.png
, Albania.png
, Algeria.png
, etc.
I have a .json file with a piece of code with all the ISO codes for each country like this:
{ "AF" : "Afghanistan", "AL" : "Albania", "DZ" : "Algeria", ... }
.png
images:
af.png
, al.png
, dz.png
, etc.I was trying to research by myself how to do this with node.js, but I am a little lost here and I would appreciate some clues a lot.
Thanks in advance!
This question is related to
javascript
node.js
rename
For linux/unix OS, you can use the shell syntax
const shell = require('child_process').execSync ;
const currentPath= `/path/to/name.png`;
const newPath= `/path/to/another_name.png`;
shell(`mv ${currentPath} ${newPath}`);
That's it!
For synchronous renaming use fs.renameSync
fs.renameSync('/path/to/Afghanistan.png', '/path/to/AF.png');
Go through http://nodejs.org/api/fs.html
One important thing - you can use sync functions also. (It will work like C program)
Source: Stackoverflow.com