ComposantsComponents

ComposantsComponents › Fichier › GestionFile › Management

tFileExist

tFileExist

Fichier › GestionFile › Management

Vérifie si un fichier ou un dossier existe, et met la réponse (true ou false) dans une variable globale. Il ne s'arrête pas en erreur quand le fichier manque : c'est un lien Run if qui lit la variable et choisit la suite, par exemple lire le fichier s'il est là, prévenir sinon. Checks whether a file or a folder exists, and puts the answer (true or false) in a global variable. It does not fail when the file is missing: a Run if link reads the variable and chooses what comes next, for example read the file if it is there, warn otherwise.

EntréeInput

Aucune : il commence son sous-job. Sinon un lien Iterate. None: it starts its subjob. Otherwise one Iterate link.

SortieOutput

Aucune : pas de flux de données. La réponse est dans les variables globales. None: no data flow. The answer is in the global variables.

Déclencheurs en sortieOutput triggers

On Subjob Ok On Subjob Error On Component Ok On Component Error Run if

On Subjob : seulement quand il commence son sous-job. On Subjob: only when it starts its subjob.

UtilisationUsage

Lire le fichier s'il est làRead the file if it is there

If row1 (Main) tFileExist_1 tFileInputDelimited_1 tLogRow_1

Condition du Run if : ((Boolean) globalMap.get("tFileExist_1_EXISTS")). Sans fichier, la lecture n'est pas lancée et le job se termine normalement. Run if condition: ((Boolean) globalMap.get("tFileExist_1_EXISTS")). Without a file, the reading is not started and the job ends normally.

Réagir à un fichier absentReact to a missing file

If tFileExist_1 tDie_1

La même condition précédée de ! : le Run if ne passe que si le fichier manque. Les deux liens peuvent partir du même tFileExist. The same condition preceded by !: the Run if only goes through if the file is missing. Both links can start from the same tFileExist.

  1. Déposez le tFileExist depuis la famille Fichier › Gestion de la palette. Drop the tFileExist from the File › Management family of the palette.
  2. Dans Nom de fichier/Flux, indiquez le chemin, en expression Java : "C:/data/in/orders.csv", context.folder + "/orders.csv". In File name/Stream, set the path, as a Java expression: "C:/data/in/orders.csv", context.folder + "/orders.csv".
  3. Reliez-le à la suite (clic droit › Déclencher › Run if) et écrivez la condition du lien avec la variable globale EXISTS. Connect it to what comes next (right-click › Trigger › Run if) and write the link condition with the EXISTS global variable.

Paramètres simplesBasic settings

Le libellé est celui de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a pas de paramètres avancés. The label is the one of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no advanced settings.

ParamètreSetting DéfautDefault VisibleShown Description
Nom de fichier/FluxFile name/StreamFILE_NAME chemin par défaut des composants + /filecomponent default path + /file ToujoursAlways Le chemin à tester, en expression Java. Un fichier ou un dossier : les deux donnent true s'ils existent. Malgré le libellé, le composant crée un java.io.File avec cette valeur : il attend un chemin, pas un flux. Un chemin relatif part du dossier de travail du job. The path to test, as a Java expression. A file or a folder: both give true if they exist. Despite the label, the component creates a java.io.File from this value: it expects a path, not a stream. A relative path starts from the working folder of the job.

Variables globalesGlobal variables

Écrites quand le composant s'exécute : avant, elles valent null. À lire dans la condition d'un Run if ou dans les composants qui suivent. Written when the component runs: before that, they are null. To read in the condition of a Run if or in the components that follow.

EXISTS Boolean
true si un fichier ou un dossier existe à ce chemin, false sinon.true if a file or a folder exists at this path, false otherwise.
FILENAME String
La valeur de Nom de fichier/Flux, telle quelle : un chemin relatif reste relatif.The value of File name/Stream, as is: a relative path stays relative.
((Boolean) globalMap.get("tFileExist_1_EXISTS"))
((String) globalMap.get("tFileExist_1_FILENAME"))

ExemplesExamples

Les sorties sont celles de la console, copiées depuis une exécution du job. Les chemins sont abrégés en C:/data. The outputs are the console ones, copied from a run of the job. The paths are shortened to C:/data.

Deux branches avec Run ifTwo branches with Run if

If If tFileExist_1 tJava_1 tJava_2
// Run if → tJava_1
((Boolean) globalMap.get("tFileExist_1_EXISTS"))
// Run if → tJava_2
!((Boolean) globalMap.get("tFileExist_1_EXISTS"))

// tJava_1
System.out.println("Found: " + globalMap.get("tFileExist_1_FILENAME"));
// tJava_2
System.out.println("Missing: " + globalMap.get("tFileExist_1_FILENAME"));

Nom de fichier/Flux : "C:/data/orders.csv", qui existe. File name/Stream: "C:/data/orders.csv", which exists.

Found: C:/data/orders.csv

"C:/data/orders_2026.csv", qui n'existe pas. "C:/data/orders_2026.csv", which does not exist.

Missing: C:/data/orders_2026.csv

Dans les deux cas, le job se termine avec le code 0 : un fichier absent n'est pas une erreur. In both cases, the job ends with exit code 0: a missing file is not an error.

Un dossier, un chemin relatifA folder, a relative path

OnSubjobOk OnSubjobOk tFileExist_1 tFileExist_2 tJava_1

tFileExist_1 : "C:/data/sub", un dossier. tFileExist_2 : "orders.csv", sans dossier. tJava_1 affiche les deux variables de chacun. tFileExist_1: "C:/data/sub", a folder. tFileExist_2: "orders.csv", without a folder. tJava_1 prints the two variables of each.

System.out.println("sub: EXISTS = "
    + globalMap.get("tFileExist_1_EXISTS")
    + ", FILENAME = "
    + globalMap.get("tFileExist_1_FILENAME"));
System.out.println("orders.csv: EXISTS = "
    + globalMap.get("tFileExist_2_EXISTS")
    + ", FILENAME = "
    + globalMap.get("tFileExist_2_FILENAME"));
sub: EXISTS = true, FILENAME = C:/data/sub
orders.csv: EXISTS = false, FILENAME = orders.csv

Le dossier existe. orders.csv est cherché dans le dossier de travail du job, pas dans C:/data : il n'y est pas. The folder exists. orders.csv is looked for in the working folder of the job, not in C:/data: it is not there.

Avant et après le composantBefore and after the component

OnSubjobOk OnSubjobOk tJava_2 tFileExist_1 tJava_1

Les deux tJava affichent globalMap.get("tFileExist_1_EXISTS") ; le fichier est "C:/data/orders.csv". Both tJava print globalMap.get("tFileExist_1_EXISTS"); the file is "C:/data/orders.csv".

Before: EXISTS = null
After the subjob: EXISTS = true

ErreursErrors

Le nom du job est remplacé par MyJob ; le message de compilation est abrégé. The job name is replaced with MyJob; the compilation message is shortened.

Condition sans conversion en BooleanCondition without a Boolean cast

Condition du Run if écrite globalMap.get("tFileExist_1_EXISTS") : Run if condition written globalMap.get("tFileExist_1_EXISTS"):

MyJob.java:488: error: incompatible types: Object cannot be converted to boolean
    if (globalMap.get("tFileExist_1_EXISTS")) {
                     ^

globalMap.get rend un Object ; la condition, recopiée dans un if, doit être un booléen. Écrivez ((Boolean) globalMap.get("tFileExist_1_EXISTS")). Le job ne compile pas et ne démarre pas. globalMap.get returns an Object; the condition, copied into an if, must be a boolean. Write ((Boolean) globalMap.get("tFileExist_1_EXISTS")). The job does not compile and does not start.

Conseils et limitesTips and limits

Un fichier absent n'arrête rienA missing file stops nothing

Le composant réussit dans les deux cas : un On Subjob Ok ou un On Component Ok passe aussi quand le fichier manque. Seul un Run if sur EXISTS distingue les deux cas ; pour arrêter le job, faites-le suivre d'un tDie. The component succeeds in both cases: an On Subjob Ok or an On Component Ok also goes through when the file is missing. Only a Run if on EXISTS tells the two cases apart; to stop the job, follow it with a tDie.

Un dossier compte aussiA folder counts too

EXISTS vaut true pour un dossier comme pour un fichier. Si un dossier peut porter le nom attendu, ne concluez pas qu'il y a un fichier à lire. EXISTS is true for a folder as for a file. If a folder can have the expected name, do not conclude that there is a file to read.

Chemins absolusAbsolute paths

Un chemin relatif dépend du dossier d'où le job est lancé, qui change selon la façon de le lancer. Préférez un chemin complet, ou une variable de contexte qui le donne. A relative path depends on the folder the job is started from, which changes with the way it is started. Prefer a full path, or a context variable that gives it.

Dans une boucleIn a loop

Relié par Iterate (après un tFileList ou un tLoop), il teste un chemin à chaque itération ; les variables sont réécrites à chaque fois. Connected with Iterate (after a tFileList or a tLoop), it tests a path at each iteration; the variables are written again each time.

Voir aussiSee also