Send file to Duplicated folder, only if the file exists on the destination folder

Running FileBot from the console, Groovy / FileBot scripting, shell scripts, etc
Post Reply
uniqedumx
Posts: 11
Joined: 23 Aug 2021, 20:56

Send file to Duplicated folder, only if the file exists on the destination folder

Post by uniqedumx »

Hello friends, excuse me what is the function to check if the destination file exists and thus send it to the duplicate folder.?

The script that I leave below checks if the destination folder exists but ignores the final file so if I already send a file previously in another resolution and I scan another folder with a new resolution, it takes it as a duplicate since it checks only if the destination folder exists but the new file does not.

Code: Select all

{
def altPath = 'Z:/LIBDRIVE/@cinedriveonline/'
def mainPath = 'Z:/LIBDRIVE/@cinedriveonline/1 DE LA A-Z y NUMEROS/'
def fileInfo = " - $vf [$mbps] $Languages"
def norm = {it.colon(' - ').replaceAll(/[?]/, '').replaceAll(/[!]/, '').replaceAll(/[¿]/, '').replaceAll(/[¡]/, '')};
def allNorm(path, hard, dir, info){ path + hard + '/' + dir + '/' + dir + info };

def outFull = genres.contains('Animación') ? ( allNorm(altPath, '3 ANIMACION', norm(ny), fileInfo) ) : ( hd ? allNorm(mainPath, (n =~ /^(?i)[a-z]/ ? n[0] : '1 CON NUMERACION'), norm(ny), fileInfo) : altPath + '4 RENOMANUAL/'+ norm(ny) + '/' + fn )
!(outFull as File).parentFile.exists() ? outFull : allNorm(altPath, '5 DUPLICADA', norm(ny), fileInfo)
}
Gracias
User avatar
rednoah
The Source
Posts: 20275
Joined: 16 Nov 2011, 08:59

Re: Send file to Duplicated folder, only if the file exists on the destination folder

Post by rednoah »

This use case is tricky, because your format generates the destination path, but to know if a file already exists you need to know the generated file path during file path generation, a chicken and egg problem so to say.


:!: By writing your format entirely in one Groovy expression, it is of course possible to generate multiple file paths internally, and then only return the one that doesn't yet exist. However, writing and maintaining this kind of format will require some level of programming expertise, and most examples and tutorials here in the forums won't be helpful.


:idea: A simple example might look like this:

Code: Select all

{
	['X:/1st Choice',
	 'Y:/2nd Choice',
	 'Z:/3rd Choice'
	].collect{
		// generate file path candidate
		it / plex
	}.find{ 
		// check if file path candidate already exists
		!it.exists()
	}
}
:idea: Please read the FAQ and How to Request Help.
Post Reply