cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
cchueng
Level III

Open all jsl files in a folder, find and replace text, save and close files

I want to write a script to open many jsl files in a folder. In each jsl file, I need to find a text and replace it with another text. Save each file and close it before going onto the next file in the folder. I tried to use "substitute" but did not work. Appreciate all the help!

 

//folder contains 224 jsl scripts
folderID = "T:\JMP_SCRIPTS\Openfiles n update\test\";

Files = Files In Directory(FolderID);

For(i = 1, i <= N Items(Files), i++, 

	FileID = Files[i];

//Open jsl file
	openFile = Open(folderID || FileID);

	subdt = Substitute(openFile, "99@wefghynKm0r3", "hihi");

	openFile << Save(folderID || FileID);
	Close(openFile, No Save);


);// End FOR loop
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Open all jsl files in a folder, find and replace text, save and close files

Look into using 

     Load Text File()

and

     Save Text File()

rather than using Open().

Load Text File() will bring the complete file into a single literal string variable and you will then be able to use Substitute() for the string and then save it back using the Save Text File.

Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Open all jsl files in a folder, find and replace text, save and close files

Look into using 

     Load Text File()

and

     Save Text File()

rather than using Open().

Load Text File() will bring the complete file into a single literal string variable and you will then be able to use Substitute() for the string and then save it back using the Save Text File.

Jim
cchueng
Level III

Re: Open all jsl files in a folder, find and replace text, save and close files

Facinating, thanks! It works for me!