Create a file: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
(11 intermediate revisions by 7 users not shown)
Line 1,323:
File( 'docs' ).mkdir()
File( File.separator + 'docs' ).mkdir()</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
CFURLRef url
 
url = fn URLFileURLWithPath( fn StringByExpandingTildeInPath(@"~/Desktop/output.txt") )
if (fn FileManagerCreateFileAtURL( url, NULL, NULL ) )
NSLog( @"File \"output.txt\" created." )
else
NSLog( @"Unable to create file \"output.txt\"." )
end if
 
url = fn URLFileURLWithPath( fn StringByExpandingTildeInPath(@"~/Desktop/docs") )
if (fn FileManagerCreateDirectoryAtURL( url, YES, NULL ) )
NSLog( @"Directory \"docs\" created." )
else
NSLog( @"Unabled to create directory \"docs\"." )
end if
 
HandleEvents
</syntaxhighlight>
 
=={{header|Gambas}}==
Line 1,448 ⟶ 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,551 ⟶ 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,716 ⟶ 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,039 ⟶ 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}}==
<syntaxhighlight lang="Phixmonti">"foo.bar" "w" fopen fclose</syntaxhighlight>
 
=={{header|PHP}}==
Line 2,081 ⟶ 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,604 ⟶ 2,742:
 
Wren does not currently support the creation of directories.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
// file is closed automatically after creation
Line 2,726 ⟶ 2,864:
 
<syntaxhighlight lang="zxbasic">SAVE "OUTPUT" CODE 16384,0</syntaxhighlight>
 
{{omit from|EasyLang}}
9,476

edits