cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
B1234
Level III

Loop Saving Files

Hi, I have a script where a file saves to a particular location. I am saving data files as a string of the product lot number and raw data. I want to be able to run the script multiple times for the same lot number without the files saving over themselves. I want to create some sort of loop that if the file name already exists, then it will save as  lotnumber Raw Data (1), lotnumber Raw Data (2) etc. This is what I have coded now, but I don't know how to make a loop with it. Can someone help make this a loop please?

 

 

lotnumer = 1234;

path = "C:\Users\Desktop\JMP\";

rawdatafile = (path || "_" || lotnumber || " Raw Data.jmp");

If( File Exists( rawdatafile ),
    dt << save as( path || "_" || lotnumber || " Raw Data (1).jmp" ),
    dtrlu << save as( path || "_" || lotnumber || " Raw Data.jmp" )
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Loop Saving Files

Here is a simple example that loops until no matching file is found, and then saves the file under a new incremented

lotnumer = "1234";

path = "C:\Users\Desktop\JMP\"; 

rawdatafile = (path || "_" || lotnumber || " Raw Data.jmp");

If( File Exists( rawdatafile ),
	i = 1;
	While(
		File Exists(
			path || "_" || lotnumber || " Raw Data (" || Char( i ) ||  ").jmp"),
		i++
	);
	dt << save as( path || "_" || lotnumber || " Raw Data (" || Char( i ) ||  ").jmp" );
,
	dtrlu << save as( path || "_" || lotnumber || " Raw Data.jmp" )
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Loop Saving Files

Here is a simple example that loops until no matching file is found, and then saves the file under a new incremented

lotnumer = "1234";

path = "C:\Users\Desktop\JMP\"; 

rawdatafile = (path || "_" || lotnumber || " Raw Data.jmp");

If( File Exists( rawdatafile ),
	i = 1;
	While(
		File Exists(
			path || "_" || lotnumber || " Raw Data (" || Char( i ) ||  ").jmp"),
		i++
	);
	dt << save as( path || "_" || lotnumber || " Raw Data (" || Char( i ) ||  ").jmp" );
,
	dtrlu << save as( path || "_" || lotnumber || " Raw Data.jmp" )
);
Jim
B1234
Level III

Re: Loop Saving Files

This is exactly what I needed! Thank you!

Recommended Articles