Create a file: Difference between revisions

→‎{{header|J}}: Add scripts
(added BASIC)
(→‎{{header|J}}: Add scripts)
Line 261:
=={{header|J}}==
 
The conjunction <tt>!:</tt> with a scalar <tt>1</tt> to the left (<tt>1!:</tt>) provides the underlying cross-platform support for working with files.
<lang J>
mkdir =: 1!:5@boxopen NB. define verb to make a directory
fwrite =: 1!:2 boxopen NB. define verb to write a file
 
<lang Jj>
NB. create two directories: /docs and docs:
'' 1!:2 <'/output.txt' NB. write an empty file
mkdir '/docs' ; 'docs'
1!:5 <'/docs' NB. create a directory
</lang>
 
However a number of libraries provide a more convenient/conventional interface to that underlying functionality.
<lang j>
require 'files'
NB. create two empty files named /output.txt and output.txt
'' fwrite '/output.txt' ; 'output.txt'
 
require 'general/dirutils' NB. addon package
NB. create two directories: /docs and docs:
mkdirdircreate '/docs' ; 'docs'
</lang>
 
892

edits