Attach text filesHello everyone,
I have a folder that contains 2800 text files. Each text file has 3 columns. I would like to be able to join all these text files in a single JMP file (by performing a join by line number), this JMP file would therefore have 2800*3 columns.
Remarks :
Before joining all the files, it would be necessary to add titles to the columns of each file.
Title column 1: x-filename
Title column 2: y-filename
Title column 3: filename-value
With “nomdufichier” which corresponds to the name of the file being opened.
I manage to retrieve the name of the folder and all the names of the text files to open in this folder with the following code:
// Chemin du répertoire contenant les fichiers textes
chemin_du_repertoire = "chemin\du\dossier";
// Parcourir le répertoire et obtenir les noms des fichiers
noms_fichier = Files In Directory(chemin_du_repertoire, "\*.txt");
But then I have no starting point for the rest.
Thanks for your help and answers!
Automation and ScriptingData AccessRe: Joindre fichiers textesTo get a good starting point: perform the action for one pair of files interactively with JMP and then copy the script from Enhanced Log. Then you can start modifying that JMP created script to work in your script much more easily.
Re: Attach text filesI managed to write a script that can transform text files into JMP files with the correct column titles.
However, to perform the online join of all these files, it is more difficult.
I tried with the following script:
// Chemin du dossier contenant les fichiers texte
dossier = "......";
// Obtenir la liste de tous les fichiers dans le dossier
listeFichiers = Files In Directory(dossier);
// Créer une nouvelle table pour stocker les données combinées
table = New Table("Data Table");
// Boucle pour charger et combiner les fichiers
for (i = 1, i <= N Items(listeFichiers), i++,
fichierCourant = dossier || listeFichiers[i];
dt = Open(fichierCourant);
// Ajouter les colonnes du fichier courant à la table combinée
table << Join(With(dt),By Row Number);
// Fermer le fichier courant
Close(dt, NoSave);
);Re: Joindre fichiers textesWith join you are most likely always creating a new table so you would have to also handle that. Other option is to use Update instead
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(3),
Compress File When Saved(1),
New Column("A1", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3]))
);
dt1 = New Table("Untitled 2",
Add Rows(3),
Compress File When Saved(1),
New Column("B1", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 6]))
);
wait(1);
dt << Update(
With(Data Table("Untitled 2")),
Replace Columns in Main Table(None)
);
Close(dt1, no save);
(try this also first with the interactive option)
Re: Attach text filesI wrote the script below which works well but it takes a long time to run for 2800 files.
Names Default To Here( 1 );
// Début de la mesure du temps
start=tick seconds();
// Chemin du dossier contenant les fichiers texte
dossier = "...";
// Obtenir la liste de tous les fichiers dans le dossier
listeFichiers = Files In Directory(dossier);
For ( i = 1 , i <= 2862 , i++,
Names Default To Here( 1 );
if( i == 1,
fichierCourant = dossier || listeFichiers[1];
fichierCourant1 = dossier || listeFichiers[Num(i+1)];
dt = Open(fichierCourant);
dt1 = Open(fichierCourant1);
dt << Join(
With( dt1 ),
By Row Number,
Output Table( "Sans titre.jmp" )
);
Close(dt,NoSave);
Close(dt1,NoSave);
dt = current data table();
,
dt = current data table();
fichierCourant1 = dossier || listeFichiers[Num(i+1)];
dt1 = Open(fichierCourant1);
dt << Join(
With( dt1 ),
By Row Number,
Output Table( "Sans titre.jmp" )
);
Close(dt,NoSave);
Close(dt1,NoSave);
);
);
end=tick seconds();
runtime=end-start;
durée=runtime/60;
result=(Char("La durée est de ")||Char(durée,5) || " "||Char("minutes"));
show(result);Thanks for your help !