Is the input folder(s) value saved for reference in filebot -script?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
rv23
Posts: 64
Joined: 19 Jul 2020, 15:05

Is the input folder(s) value saved for reference in filebot -script?

Post by rv23 »

Is there an easy/simple way to reference the input directory(s) specified on the command line within a script run using filebot -script?
For example:

Code: Select all

filebot -script myscript.groovy --action move Z:\some\directory -output z:\some\other\directory
Is there an easy way to find out the input directory(s) specified in the command line?, which in this example is Z:\some\directory ..
args looks to be an Array with all the files under the input folder(s)
_args has the argumentArray properties, which doesn't seem fun to parse

I see that output path is explicitly saved (_args.outputPath and _args.absoluteOutputFolder), is there some easily referenced variable for the input folder(s)?

Thanks in advance for any assistance.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Is the input folder(s) value saved for reference in filebot -script?

Post by rednoah »

args will give you the input file list:

Code: Select all

println args

rv23 wrote: 07 Aug 2021, 14:37 args looks to be an Array with all the files under the input folder(s)
How did you arrive at this conclusion? args is the list of input folders or files, unresolved by default unless otherwise specified, so it should be what you're looking for as is.


e.g.

Code: Select all

$ filebot -script "g:println args" TEST
[/volume1/TEST]
$ filebot -script "g:println args.files" TEST
[/volume1/TEST/a.txt]

:idea: If you use transformative options such as -r and --file-filter then args will be the list of effectively selected files, rather than input arguments.
:idea: Please read the FAQ and How to Request Help.
rv23
Posts: 64
Joined: 19 Jul 2020, 15:05

Re: Is the input folder(s) value saved for reference in filebot -script?

Post by rv23 »

Ah that's it.
I normally run my script using -r (recursive), which looks to transform args to the list of files. I had some scripts that I run without -r, and was using args[x] to get the input folder..
I was slow to figure out what was the difference between the scripts, and finally realized it was the -r.

Thanks for pointing that out, I ended up being impatient and with the google searching, and a little modification and I have a groovy method I can use to find the longest common path for all the files in args (when using -r).

Code: Select all

/**
 * Given an Array of files, which are all under the same directory, return the longest directory path that all files share
 * As I'm on windows, I needed both a delim and join separator as I couldn't figure out how to get it to work using \ for
 * both
 * Based on code from here: https://rosettacode.org/wiki/Find_common_directory_path#Groovy
 * @param files
 * @return String - root directory shared by all files
 */
def commonPath(String delim, String join, ArrayList<File> files){
  def pathParts = files.collect { it.toString().split(delim) }
  return pathParts.transpose().inject([match:true, commonParts:[]]) { aggregator, part ->
    aggregator.match = aggregator.match && part.every { it == part [0] }
    if (aggregator.match) { aggregator.commonParts << part[0] }
    aggregator
  }.commonParts.join(join)
}
Post Reply