ComposantsComponents › 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.
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.
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.
"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".
EXISTS.
Connect it to what comes next (right-click › Trigger › Run if) and write the link condition with the EXISTS global variable.
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.
|
É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.
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.((Boolean) globalMap.get("tFileExist_1_EXISTS"))
((String) globalMap.get("tFileExist_1_FILENAME"))
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.
// 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.
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.
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
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 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.
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.
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.
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.
tFileProperties · taille, date, droits et MD5 d'un fichiersize, date, rights and MD5 of a filetFileRowCount · compter les lignes d'un fichiercount the lines of a filetFileList · parcourir les fichiers d'un dossiergo through the files of a foldertFileTouch · créer un fichier videcreate an empty filetFileCopy · tFileDelete · copier ou supprimer le fichiercopy or delete the filetJava · choisir la branche avec Run ifchoose the branch with Run iftWaitForFile · surveiller un dossier (fichiers créés ou supprimés)watch a folder (files created or deleted)