cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
fredwcf
Level I

How to write scripts to automatically read many csv files and automatically save graphs to a specified directory

Hello, I need help.

I'm using JMP 16 and would like to write scripts to automatically complete the following tasks. Files come from laboratory .

 

1, There are 500 csv files (each file contains 1 worksheet), I want scripts, which can automate the reading of worksheets in each csv file;

2,After importing data and data editing & creating graphs,each worksheet generates 2 different graphs (for example, called graph A, B).I can handle this section.

3,The graphs are automatically named, numbered and then saved to 2 different folders (for example, called folders C,D ) at the same file directory.All the graphs of  500 csv files are saved to the folders C,D.

 

Section 1&3 are very difficult for me.Hope to give some script examples and any guidance is much appreciated.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to write scripts to automatically read many csv files and automatically save graphs to a specified directory

Here is a mock up of a method that can be used to do what you want.  There are a lot of specifics that need to added into the script, but for the most part, it should give you a good start 

Names Default To Here( 1 );

// Read all the file names
files = Files In Directory( "C:\Users\MyUserName\Documents\My Data\" );

X = N Items( files );
Y = "<Path to the folder the Excel files are in >";

For( i = 1, i < X, i++, 

	if( right(files[i],4)==".xls",

		//open jmp files for each xls files.
		dt1 = Open(
			Y || files[i], 
			Worksheets( "my xls worksheet" ), 
			Use for all sheets( 0 ), 
			Concatenate Worksheets( 0 ), 
			Create Concatenation Column( 0 ), 
			Worksheet Settings(
				1, 
				Has Column Headers( 0 ), 
				Number of Rows in Headers( 1 ), 
				Headers Start on Row( 1 ), 
				Data Starts on Row( 1 ), 
				Data Starts on Column( 1 ), 
				Data Ends on Row( 0 ), 
				Data Ends on Column( 0 ), 
				Replicated Spanned Rows( 1 ), 
				Suppress Hidden Rows( 1 ), 
				Suppress Hidden Columns( 1 ), 
				Suppress Empty Columns( 1 ), 
				Treat as Hierarchy( 0 )
			)
		);
		
	// edit and build graph for this table
	
	j1 = New Window("The Name " || char(i), <<journal);
	j2 = New Window("The Name " || char(i), <<journal);
	
	// Move graph to be saved to the C folder to j1
	j1 << journal( the display object for the graph);
		
	// Move graph to be saved to the D folder to j2
	j2 << journal( the display object for the graph);
	
	// Save the file
	j1 << save journal("path and filename.jrn");
	jd << save journal("path and filename.jrn");
	
	// Delete the various files from this iteration
	j1 << close window;
	j2 << close window;
	close( dt1, nosave );
	// close the graph window
	// close the report window
);
	
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to write scripts to automatically read many csv files and automatically save graphs to a specified directory

  1. See the Multiple File Import() function in the Scripting Index
  2. You are handling this section
  3. This is a simple task, if you can specify what the rules are for the naming convention, and where do the numbers come in.....will there be graphs with the same name and you will want to add a number to the name?
Jim
fredwcf
Level I

Re: How to write scripts to automatically read many csv files and automatically save graphs to a specified directory

Hi,txnelson,

Thank you very much for your help.

1、You seem to have misunderstood what I meant. I don't mean MFI. I don't want the script to import all these files into one data table at once, but to process one csv file at a time (importing\editing\graph building\saving)and then automatically process the next one.

3、The graphs are with the same name and I want to add both date and number to the name.would you like to give me some examples?

 

Thanks

PREVIEW
 
 
 
txnelson
Super User

Re: How to write scripts to automatically read many csv files and automatically save graphs to a specified directory

Here is a mock up of a method that can be used to do what you want.  There are a lot of specifics that need to added into the script, but for the most part, it should give you a good start 

Names Default To Here( 1 );

// Read all the file names
files = Files In Directory( "C:\Users\MyUserName\Documents\My Data\" );

X = N Items( files );
Y = "<Path to the folder the Excel files are in >";

For( i = 1, i < X, i++, 

	if( right(files[i],4)==".xls",

		//open jmp files for each xls files.
		dt1 = Open(
			Y || files[i], 
			Worksheets( "my xls worksheet" ), 
			Use for all sheets( 0 ), 
			Concatenate Worksheets( 0 ), 
			Create Concatenation Column( 0 ), 
			Worksheet Settings(
				1, 
				Has Column Headers( 0 ), 
				Number of Rows in Headers( 1 ), 
				Headers Start on Row( 1 ), 
				Data Starts on Row( 1 ), 
				Data Starts on Column( 1 ), 
				Data Ends on Row( 0 ), 
				Data Ends on Column( 0 ), 
				Replicated Spanned Rows( 1 ), 
				Suppress Hidden Rows( 1 ), 
				Suppress Hidden Columns( 1 ), 
				Suppress Empty Columns( 1 ), 
				Treat as Hierarchy( 0 )
			)
		);
		
	// edit and build graph for this table
	
	j1 = New Window("The Name " || char(i), <<journal);
	j2 = New Window("The Name " || char(i), <<journal);
	
	// Move graph to be saved to the C folder to j1
	j1 << journal( the display object for the graph);
		
	// Move graph to be saved to the D folder to j2
	j2 << journal( the display object for the graph);
	
	// Save the file
	j1 << save journal("path and filename.jrn");
	jd << save journal("path and filename.jrn");
	
	// Delete the various files from this iteration
	j1 << close window;
	j2 << close window;
	close( dt1, nosave );
	// close the graph window
	// close the report window
);
	
Jim