listing files from working directory
Hello
Context: I collect files from my banks and rename them to the following format : isosstartdate_ Bank_account_iosenddate. The issue I have is that one bank is providing the statement closure date in the name but not the the initial date of the statement. One way I wanted to overturn that was by fetching the end date within the filename of the previous statement file in order to use it as the start date of the new one.
A sample of javascript code I planned to use includes:
import * as fs from 'node:fs';
var files = fs.readdirSync(working_directory);
The working directory being the directory the AR application uses.
Tried to use the instruction : import * as fs from 'node:fs'; but I get an error Invalid input pre script: uncaught: 'parse error (line 1)'
Any workaround to suggest ?
Thank you
Context: I collect files from my banks and rename them to the following format : isosstartdate_ Bank_account_iosenddate. The issue I have is that one bank is providing the statement closure date in the name but not the the initial date of the statement. One way I wanted to overturn that was by fetching the end date within the filename of the previous statement file in order to use it as the start date of the new one.
A sample of javascript code I planned to use includes:
import * as fs from 'node:fs';
var files = fs.readdirSync(working_directory);
The working directory being the directory the AR application uses.
Tried to use the instruction : import * as fs from 'node:fs'; but I get an error Invalid input pre script: uncaught: 'parse error (line 1)'
Any workaround to suggest ?
Thank you
Reply to #1:
Hi Laurent,
Advanced Renamer doesn't allow the use of external modules like node.js; so importing modules just doesn't work. That is for security, and I totally agree with Kim Jensen's decision to do that (even though I'd like to have the those capabilities :).
If you have all your files in the files list you can interrogate the filenames using something like this:
ind = item.index ;
lim = (app.parseTags('<Num Files>') * 1)-1 ;
app.log( "lim = " + lim ) ;
test = 0 ;
while ( test < lim ) {
if ( ind == 0 ) {
app.log( app.getItem( test ).name ) ;
}
test++
}
If you run that code on a set of files, then check the log, you'll see the names of your files. You would need to do something like capture the names in an array or other iterable and then do whatever you need against that iterable.
If I can help let me know, my friend.
Best,
DF
Hi Laurent,
Advanced Renamer doesn't allow the use of external modules like node.js; so importing modules just doesn't work. That is for security, and I totally agree with Kim Jensen's decision to do that (even though I'd like to have the those capabilities :).
If you have all your files in the files list you can interrogate the filenames using something like this:
ind = item.index ;
lim = (app.parseTags('<Num Files>') * 1)-1 ;
app.log( "lim = " + lim ) ;
test = 0 ;
while ( test < lim ) {
if ( ind == 0 ) {
app.log( app.getItem( test ).name ) ;
}
test++
}
If you run that code on a set of files, then check the log, you'll see the names of your files. You would need to do something like capture the names in an array or other iterable and then do whatever you need against that iterable.
If I can help let me know, my friend.
Best,
DF