I have a bunch of photo's with specified names downloaded from an api. But instead using there short name I want to rename them to there fullname. Is there away to do that with a script I don't want to do it manual because there are to much. Some thing like this maybe?
$.each(priceData.result, function (index, item) {
$.each(allCoinData.result, function (allCoinIndex, allCoinItem) {
if (allCoinItem.Currency == item.MarketName.substr(4) && item.MarketName.substr(0, 4) == 'BTC-')
change src'assets/media/Bittrex/"+ allCoinItem.Currency +".png' to src'assets/media/Bittrex/"+ allCoinItem.CurrencyLong +".png'
Is something possible? I can also create an array of the photo's I need to change and an array of the names they need to change in.
You can use jQuery to get the image by its source and change it:
$.each(priceData.result, function (index, item) {
$.each(allCoinData.result, function (allCoinIndex, allCoinItem) {
if (allCoinItem.Currency == item.MarketName.substr(4) && item.MarketName.substr(0, 4) == 'BTC-')
$("img[src='assets/media/Bittrex/"+ allCoinItem.Currency +".png']")
.attr("src","assets/media/Bittrex/"+ allCoinItem.CurrencyLong +".png");
Edit
Per request to change the actual file names in windows, given the arrays you said you can make you can use this script.
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var srcFiles =["fn.js"]; // array of source file names
var destFiles =["fn-out.js"]; // array of source file names
var CurDir = fso.GetFolder(".");
var Files = CurDir.Files;
for(var i=0;i<srcFiles.length;i++)
{
if (fso.FileExists(srcFiles[i]))
{
fso.CopyFile(srcFiles[i],destFiles[i])
}
}
You will need to save that code into a file in the directory the files are in with a .js
extensions, for example fn.js
. You will then need to open a windows command prompt in that directory by holding shift and right clicking on white space in that directory and choosing open command window here.
In the command window enter the command cscript [filename]
where [filename]
is the name of the file you saved the above script in and hit enter.
For example:
cscript fn.js
When the program completes, all of the files named in srcFiles will be copied to destFiles.