Issue with CSV Access in Script Method (app.csvRowCount Undefined)

#1 : 08/07-25 08:12
Saad
Posts: 5
Hallo,
I am using Advanced Renamer version 4.13 (Free / Not Registered), and I’m encountering an issue with the scripting engine when trying to use the Pre Batch Script method in combination with CSV import.

The CSV is correctly imported (I can verify it with <Csv:2> tag and New Name method), but in the Pre Batch Script, the `app.csvRowCount` and `app.getCsvValue()` functions are returning `undefined`.

Steps I followed:
- Loaded a valid UTF-8 CSV with `;` as separator
- Used the CSV tag <Csv:2> in "New Name" method — it works fine
- Tried to populate a JS object in Pre Batch Script using:

```javascript
var csvMap = {};
for (var i = 0; i < app.csvRowCount; i++) {
var key = app.getCsvValue(i, 0);
var value = app.getCsvValue(i, 1);
csvMap[key] = value;
}
Thanks in Advance
#2 : 08/07-25 09:07
Kim Jensen
Administrator
Posts: 1002
Reply to #1:
There are no such methods. app.csvRowCount and app.getCsvValue are not methods of Advanced Renamer. Where did you see those?

You can use the CSV tags in the same way as you do in New Name method, like this:

return app.parseTags('<CSV:10>');


FYI: I am planning to make it easier to use external data sources in scripting.
#3 : 08/07-25 09:09
Delta Foxtrot
Posts: 521
Reply to #2:

Kim: AWESOME! (raising wine glass in toast)

Congrats on post 1000, BTW.

Saad: if you search the forum there are some earlier posts about using CSVs, they were a great help to me. You can probably find them just by searching on "csv".

If you load a csv in the pre-batch script as an array it's relatively "easy" to deal with situations like you are describing.

Best,
DF

edited: 08/07-25 09:18
#4 : 08/07-25 09:31
Saad
Posts: 5
Reply to #2:

Hi Kim,

Thank you very much for the quick reply...I'm new to Advanced Renamer and I'm looking for a list of script methods with CSV, but I can't find it. So I tried asking Chatgpt, and the answer was this method

Best regards
#5 : 08/07-25 09:37
Saad
Posts: 5
Reply to #3:

Hi DF,

Thanks for the tip – I will definitely check out the previous posts on CSVs.

Best regards
#6 : 08/07-25 10:45
Chris
Posts: 38
Reply to #4:

> So I tried asking Chatgpt

Thanks for the warning! :)

Sorry I can't suggest a solution. Good luck!

edited: 08/07-25 10:48
#7 : 08/07-25 12:48
Kim Jensen
Administrator
Posts: 1002
Reply to #3:
Delta: Thx ... it only took me 15 years to reach 1000 posts.

I didn't think about loading a CSV in the pre batch as a transformed array. That is a good idea.
#8 : 08/07-25 12:49
Kim Jensen
Administrator
Posts: 1002
Reply to #4:
ChatGPT is great at helping with use of Advanced Renamer for the basic stuff. But when it comes to more advanced or niche actions, it falls short and will in some cases just make up stuff.
#9 : 08/07-25 14:28
Saad
Posts: 5
Reply to #6:

I’ve found the solution with this code, and it’s working as expected..... Thanks anyway

var match = item.name.match(/^(\d+)(_.*)?/);
if (!match) return item.name;

var base = match[1];
var suffix = match[2] || "";

var newBase = app.parseTags('<Csv:2:' + base + '>');
if (!newBase || newBase === ('<Csv:2:' + base + '>')) {
return item.name;
}

return newBase + suffix;
#10 : 08/07-25 14:30
Saad
Posts: 5
Reply to #7:

I'm sure it will be a great addition or feature! It could really help people make more complex changes more easily.
#11 : 08/07-25 18:19
Chris
Posts: 38
Reply to #9:

> var newBase = app.parseTags('<Csv:2:' + base + '>');

You might want to consider that there's no such tag documented. The nearest is as Kim said:<Csv:x>.


edited: 08/07-25 18:21