Create a file: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Omitted EasyLang)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(7 intermediate revisions by 5 users not shown)
Line 1,471:
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.io.File;
import java.io.IOException;
</syntaxhighlight>
<syntaxhighlight lang="java">
void create() throws IOException {
File file = new File("output.txt");
/* create an empty file */
file.createNewFile();
File directory = new File("docs/");
/* create all parent directories */
directory.mkdirs();
File rootDirectory = new File("/docs/");
rootDirectory.mkdirs();
}
</syntaxhighlight>
<br />
An alternate implementation
<syntaxhighlight lang="java">import java.io.*;
public class CreateFileTest {
Line 1,574 ⟶ 1,592:
=={{header|LabVIEW}}==
{{VI solution|LabVIEW_Create_a_file.png}}
 
=={{header|Lang}}==
{{libheader|lang-io-module}}
<syntaxhighlight lang="lang">
# Load the IO module
# Replace "<pathToIO.lm>" with the location where the io.lm Lang module was installed to without "<" and ">"
ln.loadModule(<pathToIO.lm>)
 
$file1 = [[io]]::fp.openFile(output.txt)
[[io]]::fp.createFile($file1)
[[io]]::fp.closeFile($file1)
 
$file2 = [[io]]::fp.openFile(/output.txt)
[[io]]::fp.createFile($file2)
[[io]]::fp.closeFile($file2)
 
$dir1 = [[io]]::fp.openFile(docs)
[[io]]::fp.makeDirectory($dir1)
[[io]]::fp.closeFile($dir1)
 
$dir2 = [[io]]::fp.openFile(/docs)
[[io]]::fp.makeDirectory($dir2)
[[io]]::fp.closeFile($dir2)
</syntaxhighlight>
 
=={{header|Lasso}}==
Line 1,739 ⟶ 1,781:
}
MakeDirAndFile
</syntaxhighlight>
 
=={{header|M6809 Assembler}}==
<syntaxhighlight lang="M6809 Assembler">
nam create_file
ttl M6809 Program to create a file and a directory
*
* M6809 Assembler running under the OS-9 Operating System
* built with: asm cf.a L O=cf #32k
*
ifp1
use /DD/defs/os9.d
endc
*
mod PRGSIZ,PRGNAM,TYPE,REVS,START,SIZE
PRGNAM fcs /cf/
TYPE set Prgrm+Objct
REVS set ReEnt+1
 
HEREF fcs './output.txt'
fcb $0D
ROOTF fcs '/dd/output.txt'
fcb $0D
HERED fcs './docs'
fcb $0D
ROOTD fcs '/dd/docs'
fcb $0D
rmb 250
rmb 200
SIZE equ .
*
START equ *
leax HEREF,pcr
lda #UPDAT.
ldb #READ.+WRITE.+PREAD.+PWRIT.
os9 I$Create
leax ROOTF,pcr
lda #UPDAT.
ldb #READ.+WRITE.+PREAD.+PWRIT.
os9 I$Create
leax HERED,pcr
lda #UPDAT.
ldb #READ.+WRITE.+PREAD.+PWRIT.
os9 I$MakDir
leax ROOTD,pcr
lda #UPDAT.
ldb #READ.+WRITE.+PREAD.+PWRIT.
os9 I$MakDir
clrb
os9 F$Exit
emod
PRGSIZ equ *
END
 
</syntaxhighlight>
 
Line 2,062 ⟶ 2,158:
=={{header|Phix}}==
Copy of [[Create_a_file#Euphoria|Euphoria]], modified to display a warning when it cannot create a file in the system root (as such is typically banned on more recent operating systems)
<!--<syntaxhighlight lang="phix">integer fn(phixonline)-->
<span style="color: #004080;">integer</span> <span style="color: #000000;">fn</span>
-- In the current working directory
<span style="color: #000080;font-style:italic;">-- In the current working directory</span>
system("mkdir docs",2)
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"mkdir docs"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
fn = open("output.txt","w")
<span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">open</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"output.txt"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"w"</span><span style="color: #0000FF;">)</span>
close(fn)
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
-- In the filesystem root
<span style="color: #000080;font-style:italic;">-- In the filesystem root</span>
system("mkdir \\docs",2)
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"mkdir \\docs"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
fn = open("\\output.txt","w")
<span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">open</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"\\output.txt"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"w"</span><span style="color: #0000FF;">)</span>
if fn=-1 then
<span style="color: #008080;">if</span> <span style="color: #000000;">fn</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
puts(1,"unable to create \\output.txt\n")
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"unable to create \\output.txt\n"</span><span style="color: #0000FF;">)</span>
else
<span style="color: #008080;">else</span>
close(fn)
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
end if</syntaxhighlight>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
 
=={{header|Phixmonti}}==
Line 2,107 ⟶ 2,205:
open file (output) title ('/OUTPUT.TXT,type(text),recsize(100)' );
close file (output);
</syntaxhighlight>
 
=={{header|Plain English}}==
When I tested this program, it did not create "output.txt" in the filesystem root.
<syntaxhighlight lang="text">
To run:
Start up.
\ In the current working directory
Create ".\output.txt" in the file system.
Create ".\docs\" in the file system.
\ In the filesystem root
Create "C:\output.txt" in the file system.
Create "C:\docs\" in the file system.
Shut down.
</syntaxhighlight>
 
Line 2,630 ⟶ 2,742:
 
Wren does not currently support the creation of directories.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
// file is closed automatically after creation
9,476

edits