Page 1 of 1

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

Posted: 07 Oct 2021, 17:36
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)

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

Posted: 08 Oct 2021, 03:52
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'
		// generate file path candidate
		it / plex
		// check if file path candidate already exists