<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script to copy script file code into a text file and then be able to read out in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888406#M105071</link>
    <description>&lt;P&gt;This doesn't really differ from text parsing and you can quite easily do it with JSL. If we assume that we have combined file like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//##label script.jsl
//rev 5-9-25

names default to here(1);

dt=current datatable();

selected_rows=dt&amp;lt;&amp;lt;get selected rows();


//##Make a PDF of a data table.jsl

names default to here(1);

show(1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and it should be separated into label script.jsl and&amp;nbsp;Make a PDF of a data table.jsl, I would do something like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

path = "$DOWNLOADS/comb_script.jsl";
save_path = "$DOWNLOADS/";
separator = "//##";


txt = Load Text File(path);
lines = Words(txt, "\!N");

aa_scripts = Associative Array();
cur_filename = "";
For Each({line}, lines,
	If(Starts With(line, separator), // new file
		filename = Substitute(line, separator, "");
		cur_filename = filename;
		aa_scripts[cur_filename] = {};
	,
		Insert Into(aa_scripts[cur_filename], line);
	);
);

For Each({{filename, script_lines}}, aa_scripts,
	script_txt = Concat Items(script_lines, "\!N");
	Save Text File(save_path || filename, script_txt);
);

Write();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do note that this will remove extra row changes from your data due to how Words works. If you wish to keep them, you can&amp;nbsp;loop over the text using Contains and Substr or something similar&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

path = "$DOWNLOADS/comb_script.jsl";
save_path = "$DOWNLOADS/";
separator = "//##";


txt = Load Text File(path);

While(Length(txt) &amp;gt; 0,
	separator_start = Contains(txt, separator);
	separator_end = Contains(txt, separator, separator_start + 1);
	If(separator_end == 0,
		separator_end = Length(txt) + 1;
	);
	cur_script = Remove From(txt, 1, separator_end - separator_start);
	cur_filename = Remove From(cur_script, 1, Contains(cur_script, "\!N") - 1);
	cur_script = Trim Whitespace(cur_script);
	filename = Substitute Into(cur_filename, separator, "");
	
	Save Text File(save_path || cur_filename, cur_script);	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Jul 2025 05:14:53 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2025-07-22T05:14:53Z</dc:date>
    <item>
      <title>Script to copy script file code into a text file and then be able to read out</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888095#M105029</link>
      <description>&lt;P&gt;Hey user group!&lt;/P&gt;
&lt;P&gt;I had a question on how to create a scrip that would 1: loop through a folder that contains a bunch of scripts, copy the name of the script file and then copy the script itself below the name into a text file and keep concatenating the text file with all the scripts from the folder 2: Be able to read in the text from the text file and create new script files into a chosen folder.&amp;nbsp; I can create the user interface side to choose what to do (save out or read in) and select the folders no problem but not sure on how to save the file name and script to the text file or read it in.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example the text file it would have crated would look like this:&lt;/P&gt;
&lt;P&gt;script one&lt;/P&gt;
&lt;P&gt;names default to here(1);&lt;/P&gt;
&lt;P&gt;dt1=current data table();&lt;/P&gt;
&lt;P&gt;script two&lt;/P&gt;
&lt;P&gt;names default to here(1);&lt;/P&gt;
&lt;P&gt;dt2=current data table();&lt;/P&gt;
&lt;P&gt;script 3&lt;/P&gt;
&lt;P&gt;names default to here(1);&lt;/P&gt;
&lt;P&gt;dt3=current data table();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and when read would output three script files each containing the code that was under the file name in the text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions would be appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2025 22:51:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888095#M105029</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2025-07-18T22:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Script to copy script file code into a text file and then be able to read out</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888108#M105030</link>
      <description>&lt;P&gt;Is there specific reason of combining the scripts like this instead of using Include?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creating the text file is simple, below is one example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

path = "folder/";
path = Convert File Path(path, "windows");

scriptfiles = Files In Directory(path);

scripts = {};

For Each({filename}, scriptfiles,
	If(!Ends With(filename, ".jsl"),
		continue();
	);
	Insert Into(scripts, "//" || filename);
	Insert Into(scripts, Load Text File(path || filename));
);

txt = Concat Items(scripts, "\!N");
Save Text File(path || "total.jsl", txt, mode("replace"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but creating the script files might not be as easy. How do you differentiate between JSL and file name? Do you have very specific file names?&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jul 2025 05:23:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888108#M105030</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-07-19T05:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Script to copy script file code into a text file and then be able to read out</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888368#M105068</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;, this worked pretty well!&lt;/P&gt;
&lt;P&gt;I changed the start of a file to a more distinct text&amp;nbsp; of "//##" so now the text file looks like this&lt;/P&gt;
&lt;P&gt;//##label script.jsl&lt;BR /&gt;//rev 5-9-25&lt;/P&gt;
&lt;P&gt;names default to here(1);&lt;/P&gt;
&lt;P&gt;dt=current datatable();&lt;/P&gt;
&lt;P&gt;selected_rows=dt&amp;lt;&amp;lt;get selected rows();&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;//##Make a PDF of a data table.jsl&lt;/P&gt;
&lt;P&gt;etc......&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now I would know that //## signals the start of a new script file and&amp;nbsp; that the name of the file lies between the //## and .jsl.&amp;nbsp; I would also know that between .jsl and the next //## is the text of the script.&amp;nbsp; So it looks like all the identifiers are there, just wondering if there is a way in JSL to read through the code in this way that can take advantage of these identifiers to reconstruct the files or if I'd have to do that portion of it in a different program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for any additional thoughts!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2025 22:58:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888368#M105068</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2025-07-21T22:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Script to copy script file code into a text file and then be able to read out</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888406#M105071</link>
      <description>&lt;P&gt;This doesn't really differ from text parsing and you can quite easily do it with JSL. If we assume that we have combined file like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//##label script.jsl
//rev 5-9-25

names default to here(1);

dt=current datatable();

selected_rows=dt&amp;lt;&amp;lt;get selected rows();


//##Make a PDF of a data table.jsl

names default to here(1);

show(1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and it should be separated into label script.jsl and&amp;nbsp;Make a PDF of a data table.jsl, I would do something like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

path = "$DOWNLOADS/comb_script.jsl";
save_path = "$DOWNLOADS/";
separator = "//##";


txt = Load Text File(path);
lines = Words(txt, "\!N");

aa_scripts = Associative Array();
cur_filename = "";
For Each({line}, lines,
	If(Starts With(line, separator), // new file
		filename = Substitute(line, separator, "");
		cur_filename = filename;
		aa_scripts[cur_filename] = {};
	,
		Insert Into(aa_scripts[cur_filename], line);
	);
);

For Each({{filename, script_lines}}, aa_scripts,
	script_txt = Concat Items(script_lines, "\!N");
	Save Text File(save_path || filename, script_txt);
);

Write();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do note that this will remove extra row changes from your data due to how Words works. If you wish to keep them, you can&amp;nbsp;loop over the text using Contains and Substr or something similar&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

path = "$DOWNLOADS/comb_script.jsl";
save_path = "$DOWNLOADS/";
separator = "//##";


txt = Load Text File(path);

While(Length(txt) &amp;gt; 0,
	separator_start = Contains(txt, separator);
	separator_end = Contains(txt, separator, separator_start + 1);
	If(separator_end == 0,
		separator_end = Length(txt) + 1;
	);
	cur_script = Remove From(txt, 1, separator_end - separator_start);
	cur_filename = Remove From(cur_script, 1, Contains(cur_script, "\!N") - 1);
	cur_script = Trim Whitespace(cur_script);
	filename = Substitute Into(cur_filename, separator, "");
	
	Save Text File(save_path || cur_filename, cur_script);	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jul 2025 05:14:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-copy-script-file-code-into-a-text-file-and-then-be/m-p/888406#M105071</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-07-22T05:14:53Z</dc:date>
    </item>
  </channel>
</rss>

