Create a file: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
(47 intermediate revisions by 36 users not shown)
Line 6:
=={{header|11l}}==
{{trans|Python}}
<langsyntaxhighlight lang="11l">L(directory) [‘/’, ‘./’]
File(directory‘output.txt’, ‘w’) // create /output.txt, then ./output.txt
fs:create_dir(directory‘docs’) // create directory /docs, then ./docs</langsyntaxhighlight>
 
=={{header|4DOS Batch}}==
<langsyntaxhighlight lang="4dos">echos > output.txt
mkdir docs
 
echos > \output.txt
mkdir \docs</langsyntaxhighlight>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program createDirFic64.s */
 
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
.equ MKDIRAT, 0x22 // Linux Syscall create directory
.equ CHGDIR, 0x31 // Linux Syscall change directory
 
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessCreateDirOk: .asciz "Create directory Ok.\n"
szMessErrCreateDir: .asciz "Unable create directory. \n"
szMessErrChangeDir: .asciz "Unable change directory. \n"
szMessCreateFileOk: .asciz "Create file Ok.\n"
szMessErrCreateFile: .asciz "Unable create file. \n"
szMessErrCloseFile: .asciz "Unable close file. \n"
szNameDir: .asciz "Dix1"
szNameFile: .asciz "file1.txt"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
// create directory
mov x0,AT_FDCWD
ldr x1,qAdrszNameDir // directory name
mov x2,0775 // mode (in octal zero is important !!)
mov x8,MKDIRAT // code call system create directory
svc 0 // call systeme
cbnz x0,99f // error ?
// display message ok directory
ldr x0,qAdrszMessCreateDirOk
bl affichageMess
// change directory
ldr x0,qAdrszNameDir // directory name
mov x8, #CHGDIR // code call system change directory
svc #0 // call systeme
cbnz x0,98f // error ?
// create file
mov x0,AT_FDCWD // current directory
ldr x1,qAdrszNameFile // directory name
mov x2,O_CREAT|O_WRONLY // flags
mov x3,0644 // this zone is Octal number (0 before)
mov x8,OPEN // code call system open file
svc #0 // call systeme
cmp x0,#0 // error ?
ble 97f
mov x19,x0 // save File Descriptor
// display message ok file
ldr x0,qAdrszMessCreateFileOk
bl affichageMess
// close file
mov x0,x19 // Fd
mov x8,CLOSE // close file
svc 0
cbnz x0,96f // error ?
mov x0,0 // return code Ok
b 100f // end Ok
96: // display error message close file
ldr x0,qAdrszMessErrCloseFile
bl affichageMess
mov x0,1 // return code error
b 100f
97: // display error message create file
ldr x0,qAdrszMessErrCreateFile
bl affichageMess
mov x0,1 // return code error
b 100f
98: // display error message change directory
ldr x0,qAdrszMessErrChangeDir
bl affichageMess
mov x0,1 // return code error
b 100f
99: // display error message create directory
ldr x0,qAdrszMessErrCreateDir
bl affichageMess
mov x0,1 // return code error
b 100f
100: // standard end of the program
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrszMessCreateDirOk: .quad szMessCreateDirOk
qAdrszMessErrCreateDir: .quad szMessErrCreateDir
qAdrszMessErrChangeDir: .quad szMessErrChangeDir
qAdrszMessCreateFileOk: .quad szMessCreateFileOk
qAdrszNameFile: .quad szNameFile
qAdrszMessErrCreateFile: .quad szMessErrCreateFile
qAdrszMessErrCloseFile: .quad szMessErrCloseFile
qAdrszNameDir: .quad szNameDir
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 
</syntaxhighlight>
 
=={{header|Action!}}==
The attached result has been obtained under DOS 2.5.
<syntaxhighlight lang="action!">PROC Dir(CHAR ARRAY filter)
CHAR ARRAY line(255)
BYTE dev=[1]
 
Close(dev)
Open(dev,filter,6)
DO
InputSD(dev,line)
PrintE(line)
IF line(0)=0 THEN
EXIT
FI
OD
Close(dev)
RETURN
 
PROC CreateFile(CHAR ARRAY fname)
BYTE dev=[1]
 
Close(dev)
Open(dev,fname,8)
Close(dev)
RETURN
 
PROC Main()
CHAR ARRAY filter="D:*.*", fname="D:OUTPUT.TXT"
 
PrintF("Dir ""%S""%E",filter)
Dir(filter)
 
PrintF("Create file ""%S""%E%E",fname)
CreateFile(fname)
 
PrintF("Dir ""%S""%E",filter)
Dir(filter)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Create_a_file.png Screenshot from Atari 8-bit computer]
<pre>
Dir "D:*.*"
DOS SYS 037
DUP SYS 042
628 FREE SECTORS
 
Create file "D:OUTPUT.TXT"
 
Dir "D:*.*"
DOS SYS 037
DUP SYS 042
OUTPUT TXT 001
627 FREE SECTORS
</pre>
 
=={{header|Ada}}==
Line 21 ⟶ 191:
* Use Streams_IO to write 0 bytes. File creation with Ada.Text_IO does not create 0 byte files (it inserts EOL/EOF).<br>
* The forward slash (/) notation works in Windows XP as well as Unix/Linux.
<langsyntaxhighlight lang="ada">with Ada.Streams.Stream_IO, Ada.Directories;
use Ada.Streams.Stream_IO, Ada.Directories;
 
Line 37 ⟶ 207:
Create_Directory("/docs");
end File_Creation;</langsyntaxhighlight>
 
=={{header|Aikido}}==
<langsyntaxhighlight lang="aikido">
var sout = openout ("output.txt") // in current dir
sout.close()
Line 50 ⟶ 220:
mkdir ("/docs")
 
</syntaxhighlight>
</lang>
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime"># Make a directory using the -mkdir- program
void
mkdir(text p)
Line 89 ⟶ 259:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 98 ⟶ 268:
{{works with|ALGOL 68|Standard - no extensions to language used}}
It may be best to to use an operating system provided library.
<langsyntaxhighlight lang="algol68">main:(
 
INT errno;
Line 135 ⟶ 305:
 
errno := mkpage("input.txt",2);
)</langsyntaxhighlight>
 
=={{header|APL}}==
<langsyntaxhighlight APLlang="apl"> 'output.txt' ⎕ncreate ¯1+⌊/0,⎕nnums
'\output.txt' ⎕ncreate ¯1+⌊/0,⎕nnums
⎕mkdir 'Docs'
⎕mkdir '\Docs'</langsyntaxhighlight>
 
=={{header|AppleScript}}==
Line 147 ⟶ 317:
 
Create a zero-byte text file on the startup disk (root directory). Note: the <code>close</code> command is a memory allocation housekeeping command that should be performed once file access is complete.
<langsyntaxhighlight AppleScriptlang="applescript ">close (open for access "output.txt")</langsyntaxhighlight>
Create a new folder (directory) on the startup disk (root directory).
<syntaxhighlight lang="applescript AppleScript ">tell application "Finder" to make new folder at startup disk with properties {name:"docs"}</langsyntaxhighlight>
Create a zero-byte text file in the frontmost (open) Finder window.
<langsyntaxhighlight AppleScriptlang="applescript ">tell application "Finder" to set wd to target of window 1 as string
close (open for access wd & "output.txt")</langsyntaxhighlight>
Create a new folder (directory) in the frontmost (open) Finder window.
<syntaxhighlight lang="applescript AppleScript ">tell application "Finder" to make new folder at window 1 with properties {name:"docs"}</langsyntaxhighlight>
--[[User:Apl.way|Apl.way]] 21:20, 9 June 2010 (UTC)
 
'''Observations on 28th February 2020:'''
 
#The command for closing a file access previously opened with <code>open for access</code> is <code>close access</code>, not <code>close</code>.
#While specifying just a file name did at one time cause the file to be created at the root level of the startup disk, this is now prevented by macOS's security measures:
##The system actively discourages the creation of files in that location.
##It's more likely to cooperate with file commands having AppleScript or application "specifiers" as parameters than it is when the parameters are merely text.
#In macOS, the "current working directory" is effectively the root level of the startup disk anyway, except in the Terminal application when "cd" is used or during a shell script containing "cd" which is being executed using AppleScript's <code>do shell script</code> command.
#In view of points 2.2 and 3 above, this task is ideally one that should not be casually performed on Mac computers.
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 288 ⟶ 467:
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">output: "output.txt"
docs: "docs"
 
write output ""
write.directory docs ø
 
write join.path ["/" output] ""
write.directory join.path ["/" docs] ø</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">FileAppend,,output.txt
FileCreateDir, docs
FileAppend,,c:\output.txt
FileCreateDir, c:\docs</langsyntaxhighlight>
 
=={{header|AWK}}==
<langsyntaxhighlight lang="awk">BEGIN {
printf "" > "output.txt"
close("output.txt")
Line 304 ⟶ 494:
system("mkdir docs")
system("mkdir /docs")
}</langsyntaxhighlight>
 
=={{header|Axe}}==
Since the TI-OS does not have a true filesystem, this task is emulated using an application variable instead of a file.
<langsyntaxhighlight lang="axe">GetCalc("appvOUTPUT",0)</langsyntaxhighlight>
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="qbasic">OPEN "output.txt" FOR OUTPUT AS 1
CLOSE
OPEN "\output.txt" FOR OUTPUT AS 1
CLOSE</langsyntaxhighlight>
 
==={{header|Applesoft BASIC}}===
There are disk volumes, but no folders in DOS 3.3.
<syntaxhighlight lang="gwbasic"> 0 D$ = CHR$ (4): PRINT D$"OPEN OUTPUT.TXT": PRINT D$"CLOSE"</syntaxhighlight>
==={{header|BaCon}}===
<langsyntaxhighlight lang="qbasic">' Create file and dir
TRAP LOCAL
 
Line 339 ⟶ 532:
 
LABEL report2
PRINT ERR$(ERROR)</langsyntaxhighlight>
 
{{out}}
Line 353 ⟶ 546:
drwxr-xr-x 2 4096 May 2 23:53 docs
drwxrwxr-x 7 12288 May 2 23:53 .</pre>
 
==={{header|Commodore BASIC}}===
 
On most Commodore 8-bit systems, the most commonly used storage devices were floppy disk drives and cassette tape drives, however these file systems are typically flat (linear) and do not feature any kind of file hierarchy. It is possible that other third-party storage devices (hard drives, etc.) may support such hierarchies, however, the commands to create, delete, and/or navigate in and out of various directories would be unique and specialized to those devices.
 
The example below illustrates the syntax for the open statement which will create the file, however, ''something'' must be written to the file or else nothing will actually be created on the disk. In this case we will simply write a single null byte.
 
Even still, the empty file will still cause Commodore DOS to allocate 1 data block to the file, as reported in a directory listing.
 
<syntaxhighlight lang="gwbasic">
10 rem create a file
20 open 10,8,10,"0:output.txt,seq,write"
30 print#10,chr$(0)
40 close 10
50 rem check device status for error
60 open 15,8,15:input#15,a,b$,c,d:print a;b$;c;d:close 15
</syntaxhighlight>
 
<pre>
RUN
0 OK 0 0
 
READY.
LOAD "$",8
 
SEARCHING FOR $
LOADING
READY.
LIST
 
0 "ROSETTA CODE " RC 2A
1 "OUTPUT.TXT" SEQ
663 BLOCKS FREE.
READY.
</pre>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">copy nul output.txt
copy nul \output.txt</langsyntaxhighlight>
 
<langsyntaxhighlight lang="dos">md docs
md \docs</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> CLOSE #OPENOUT("output.txt")
CLOSE #OPENOUT("\output.txt")
*MKDIR docs
*MKDIR \docs</langsyntaxhighlight>
 
=={{header|Blue}}==
 
Linux/x86-64. If you really want to create a file and dir in the root, prefix the paths with a slash.
 
<syntaxhighlight lang="blue">global _start
 
: syscall ( num:eax -- result:eax ) syscall ;
 
: exit ( status:edi -- noret ) 60 syscall ;
: bye ( -- noret ) 0 exit ;
: die ( err:eax -- noret ) neg exit ;
 
: unwrap ( result:eax -- value:eax ) dup 0 cmp ' die xl ;
: ordie ( result -- ) unwrap drop ;
 
: open ( pathname:edi flags:esi mode:edx -- fd:eax ) 2 syscall unwrap ;
: close ( fd:edi -- ) 3 syscall ordie ;
 
: mkdir ( pathname:edi mode:esi -- ) 83 syscall ordie ;
 
00001 const for-writing
00100 const create
01000 const truncate
 
: create-file ( pathname -- )
create for-writing or truncate or
0640 open close ;
 
: make-directory ( pathname -- ) 0750 mkdir ;
 
: create-output-file ( -- ) s" output.txt" drop create-file ;
: make-docs-directory ( -- ) s" docs" drop make-directory ;
 
: _start ( -- noret )
create-output-file
make-docs-directory
bye
;</syntaxhighlight>
 
=={{header|BQN}}==
May require elevated privileges to run correctly. Paths are relative to the script's path by default, but can be resolved relative to the shell's working directory with <code>•wdpath •file.At path</code>.
 
<syntaxhighlight lang="bqn">"output.txt" •file.Chars ""
"/output.txt" •file.Chars ""
•file.CreateDir "docs"
•file.CreateDir "/docs"</syntaxhighlight>
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat">put$(,"output.txt",NEW)</langsyntaxhighlight>
Or
<langsyntaxhighlight lang="bracmat">fil$("output.txt",w)</langsyntaxhighlight>
In the latter case the file is still open, so unless the file is implicitly flushed and closed by ending the Bracmat program, you would want to close it explicitly:
<syntaxhighlight lang ="bracmat">fil$(,SET,-1)</langsyntaxhighlight>
To create a directory we are dependent on the underlying OS. In DOS:
<langsyntaxhighlight lang="bracmat">sys$"mkdir docs"</langsyntaxhighlight>
And in the file system root:
<langsyntaxhighlight lang="bracmat">sys$"mkdir \\docs"</langsyntaxhighlight>
 
=={{header|C}}==
=== ISO C ===
ISO C (directory creation not supported):
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main() {
Line 388 ⟶ 664:
 
return 0;
}</langsyntaxhighlight>
 
=== POSIX: ===
 
{{works with|POSIX}}
<langsyntaxhighlight lang="c">#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
Line 406 ⟶ 682:
 
return 0;
}</langsyntaxhighlight>
 
(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
 
=== Windows API ===
=={{header|ChucK}}==
This creates a file in root:
<lang c>
FileIO text;
text.open("output.txt", FileIO.WRITE);
</lang>
 
First, a solution with the C runtime functions <code>_creat</code> and <code>_mkdir</code>.
=={{header|C++}}==
Uses some Microsoft library:
<lang cpp>#include <fstream>
#include <direct.h>
 
<syntaxhighlight lang="c">#include <direct.h>
int main() {
#include <io.h>
std::fstream f( "output.txt", std::ios::out );
#include <sys/stat.h>
f.close();
f.open( "/output.txt", std::ios::out );
f.close();
 
int main(void) {
_mkdir( "docs" );
int f;
_mkdir( "/docs" );
f = _creat("output.txt", _S_IWRITE);
if (f == -1) {
perror("Unable to create file");
} else {
_close(f);
}
if (_mkdir("docs") == -1) {
perror("Unable to create directory");
}
f = _creat("\\output.txt", _S_IWRITE);
if (f == -1) {
perror("Unable to create file");
} else {
_close(f);
}
if (_mkdir("\\docs") == -1) {
perror("Unable to create directory");
}
 
return 0;
}</langsyntaxhighlight>
 
Another solution with the kernel32 API functions <code>CreateFile</code> and <code>CreateDirectory</code>.
 
<syntaxhighlight lang="c">#include <windows.h>
#include <stdio.h>
 
int main(void) {
HANDLE hFile;
hFile = CreateFile("output.txt", GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("Unable to create file\n");
} else {
CloseHandle(hFile);
}
if (CreateDirectory("docs", NULL) == 0) {
printf("Unable to create directory\n");
}
 
hFile = CreateFile("\\output.txt", GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("Unable to create file\n");
} else {
CloseHandle(hFile);
}
 
if (CreateDirectory("\\docs", NULL) == 0) {
printf("Unable to create directory\n");
}
 
return 0;
}</syntaxhighlight>
 
=== OS/2 ===
 
Using the OS/2 API functions <code>DosOpen</code> and <code>DosMkDir</code>.
 
<syntaxhighlight lang="c">#include <os2.h>
 
int main(void) {
ULONG Result, ActionTaken, hFile;
Result = DosOpen("output.txt", &hFile, &ActionTaken, 0L,
FILE_NORMAL,
OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYREADWRITE,
NULL);
if (Result != 0) {
printf("Unable to create file\n");
} else {
DosClose(hFile);
}
Result = DosMkDir("docs", NULL);
if (Result != 0) {
printf("Unable to create directory\n");
}
 
Result = DosOpen("\\output.txt", &hFile, &ActionTaken, 0L,
FILE_NORMAL,
OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYREADWRITE,
NULL);
if (Result != 0) {
printf("Unable to create file\n");
} else {
DosClose(hFile);
}
Result = DosMkDir("\\docs", NULL);
if (Result != 0) {
printf("Unable to create directory\n");
}
 
return 0;
}</syntaxhighlight>
 
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">using System;
using System.IO;
 
Line 447 ⟶ 814:
Directory.CreateDirectory(@"\docs");
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
Uses some Microsoft library:
<syntaxhighlight lang="cpp">#include <direct.h>
#include <fstream>
 
int main() {
std::fstream f("output.txt", std::ios::out);
f.close();
f.open("/output.txt", std::ios::out);
f.close();
 
_mkdir("docs");
_mkdir("/docs");
 
return 0;
}</syntaxhighlight>
 
A cross-platform solution using C++17
 
<syntaxhighlight lang="cpp">#include <filesystem>
#include <fstream>
 
namespace fs = std::filesystem;
 
int main() {
std::fstream f("output.txt", std::ios::out);
f.close();
f.open("/output.txt", std::ios::out);
f.close();
 
fs::create_directory("docs");
fs::create_directory("/docs");
}</syntaxhighlight>
 
=={{header|ChucK}}==
This creates a file in root:
<syntaxhighlight lang="c">
FileIO text;
text.open("output.txt", FileIO.WRITE);
</syntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="lisp">(import '(java.io File))
(.createNewFile (new File "output.txt"))
(.mkdir (new File "docs"))
(.createNewFile (File. (str (File/separator) "output.txt")))
(.mkdir (File. (str (File/separator) "docs")))</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{works with|GnuCOBOL}} and other compilers with the system call extensions
<langsyntaxhighlight COBOLlang="cobol"> identification division.
program-id. create-a-file.
 
Line 498 ⟶ 906:
.
 
end program create-a-file.</langsyntaxhighlight>
{{out}}
<pre>
Line 516 ⟶ 924:
 
=={{header|Common Lisp}}==
Lisp provides open and close commands for I/O with files<langsyntaxhighlight lang="lisp">(let ((stream (open "output.txt" :direction :output)))
(close stream))</langsyntaxhighlight>
but it is more common to use ''with-open-file'' which has better exception handling.
<langsyntaxhighlight lang="lisp">(with-open-file (stream "output.txt" :direction :output)
;; use the stream here
)</langsyntaxhighlight>
As lisp is capable of being run on many different platforms and no assumptions should be made about the filesystem there are functions to construct paths in a platform independent manner
<langsyntaxhighlight lang="lisp">(let ((paths (list (make-pathname :directory '(:relative "docs"))
(make-pathname :directory '(:absolute "docs")))))
(mapcar #'ensure-directories-exist paths))</langsyntaxhighlight>
So creating a file called ''output.txt'' with an absolute path in the root directory becomes:
<langsyntaxhighlight lang="lisp">(with-open-file
(stream
(make-pathname :directory '(:absolute "") :name "output.txt")
:direction :output))</langsyntaxhighlight>
 
On the other hand, if you may depend on the platform's pathname syntax then shorter notation may be used:
<langsyntaxhighlight lang="lisp">(mapcar #'ensure-directories-exist '(#p"docs/" #p"/docs/")))</langsyntaxhighlight>
 
=={{header|Component Pascal}}==
{{works with| BlackBox Component Builder}}
<langsyntaxhighlight lang="oberon2">
MODULE CreateFile;
IMPORT Files, StdLog;
Line 556 ⟶ 964:
 
END CreateFile.
</syntaxhighlight>
</lang>
 
=={{header|Crystal}}==
<syntaxhighlight lang="ruby">File.write "output.txt", ""
Dir.mkdir "docs"
 
File.write "/output.txt", ""
Dir.mkdir "/docs"</syntaxhighlight>
 
=={{header|D}}==
For file creation, std.file.write function & std.stream.file class are used.<br>
For dir creation, std.file.mkdir is used.
<langsyntaxhighlight lang="d">module fileio ;
import std.stdio ;
import std.path ;
Line 605 ⟶ 1,021:
writefln("== test: File & Dir Creation ==") ;
testCreate("output.txt", "docs") ;
}</langsyntaxhighlight>
 
=={{header|Dc}}==
<syntaxhighlight lang="dc">! for d in . / ;do > "$d/output.txt" ; mkdir "$d/docs" ;done</syntaxhighlight>
 
=={{header|DCL}}==
<syntaxhighlight lang="dcl">open/write output_file output.txt
open/write output_file [000000]output.txt
create/directory [.docs]
create/directory [000000.docs]</syntaxhighlight>
 
=={{header|Delphi}}==
Line 611 ⟶ 1,036:
These functions illustrate two methods for creating text files in Delphi: standard text file I/O and filestreams.
 
<syntaxhighlight lang="delphi">
<lang Delphi>
program createFile;
 
Line 714 ⟶ 1,139:
 
 
</syntaxhighlight>
</lang>
 
=={{header|DCL}}==
<lang DCL>open/write output_file output.txt
open/write output_file [000000]output.txt
create/directory [.docs]
create/directory [000000.docs]</lang>
 
=={{header|E}}==
 
<langsyntaxhighlight lang="e"><file:output.txt>.setBytes([])
<file:docs>.mkdir(null)
<file:///output.txt>.setBytes([])
<file:///docs>.mkdir(null)</langsyntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="lisp">
;; The file system is the browser local storage
;; It is divided into named stores (directories)
Line 746 ⟶ 1,165:
(local-stores 'root) → ("root" "root/docs")
(local-stores 'user) → ("user" "user/docs")
</syntaxhighlight>
</lang>
 
=={{header|Elena}}==
ELENA 4.x :
<langsyntaxhighlight lang="elena">import system'io;
public program()
Line 761 ⟶ 1,180:
Directory.assign("\docs").create();
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">File.open("output.txt", [:write])
File.open("/output.txt", [:write])
 
File.mkdir!("docs")
File.mkdir!("/docs")</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(make-empty-file "output.txt")
<lang Lisp>
(shellmake-commanddirectory "touch output.txt & mkdir docs")
(make-empty-file "/output.txt")
(cd "~/")
(make-directory "/docs")</syntaxhighlight>
(shell-command "touch output.txt & mkdir docs")</lang>
 
 
=={{header|Erlang}}==
"/" is documented as working on Windows.
<langsyntaxhighlight lang="erlang">
-module(new_file).
-export([main/0]).
Line 788 ⟶ 1,206:
ok = file:write_file( filename:join(["/", "output.txt"]), <<>> ),
ok = file:make_dir( filename:join(["/", "docs"]) ).
</syntaxhighlight>
</lang>
 
=={{header|ERRE}}==
Filenames are in 8+3 DOS format: without drive and directory info, refer to the same directory as the ERRE program is running from; full pathnames can include drive name and directory.
You must use PC.LIB for managing directories.
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM FILE_TEST
 
Line 808 ⟶ 1,226:
 
END PROGRAM
</syntaxhighlight>
</lang>
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphroria">integer fn
 
-- In the current working directory
Line 821 ⟶ 1,239:
system("mkdir \\docs",2)
fn = open("\\output.txt","w")
close(fn)</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System.IO
[<EntryPoint>]
Line 833 ⟶ 1,251:
ignore (File.Create(Path.Combine(path, fileName)))
ignore (Directory.CreateDirectory(Path.Combine(path, dirName)))
0</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USE: io.directories
 
"output.txt" "/output.txt" [ touch-file ] bi@
"docs" "/docs" [ make-directory ] bi@</langsyntaxhighlight>
 
=={{header|Fancy}}==
<langsyntaxhighlight lang="fancy">["/", "./"] each: |dir| {
# create '/docs', then './docs'
Directory create: (dir ++ "docs")
Line 849 ⟶ 1,267:
f writeln: "hello, world!"
}
}</langsyntaxhighlight>
 
=={{header|Forth}}==
There is no means to create directories in ANS Forth.
<langsyntaxhighlight lang="forth"> s" output.txt" w/o create-file throw ( fileid) drop
s" /output.txt" w/o create-file throw ( fileid) drop</langsyntaxhighlight>
 
=={{header|Fortran}}==
Line 860 ⟶ 1,278:
Don't know a way of creating directories in Fortran
#Edit: Use system commands to create directories
<langsyntaxhighlight lang="fortran">
PROGRAM CREATION
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW") ! Current directory
Line 873 ⟶ 1,291:
 
END PROGRAM
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
' create empty file and sub-directory in current directory
Line 890 ⟶ 1,308:
 
Print "Press any key to quit"
Sleep</langsyntaxhighlight>
 
=={{header|friendly interactive shell}}==
{{trans|UNIX Shell}}
<langsyntaxhighlight lang="fishshell">touch {/,}output.txt # create both /output.txt and output.txt
mkdir {/,}docs # create both /docs and docs</langsyntaxhighlight>
 
=={{header|FunL}}==
{{trans|Scala}}
<langsyntaxhighlight lang="funl">import io.File
 
File( 'output.txt' ).createNewFile()
File( File.separator + 'output.txt' ).createNewFile()
File( 'docs' ).mkdir()
File( File.separator + 'docs' ).mkdir()</langsyntaxhighlight>
 
=={{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}}==
'''[https://gambas-playground.proko.eu/?gist=abe59d5d62a4d01817638115e75e7e29 Click this link to run this code]'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
Dim byCount As Byte
Dim sToSave As String
Line 919 ⟶ 1,360:
Print File.Load(User.Home &/ "TestFile")
 
End</langsyntaxhighlight>
Output:
<pre>
Line 931 ⟶ 1,372:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 962 ⟶ 1,403:
createDir("docs")
createDir("/docs")
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">new File("output.txt").createNewFile()
new File(File.separator + "output.txt").createNewFile()
new File("docs").mkdir()
new File(File.separator + "docs").mkdir()</langsyntaxhighlight>
 
=={{header|Haskell}}==
 
<langsyntaxhighlight lang="haskell">import System.Directory
 
createFile name = writeFile name ""
Line 980 ⟶ 1,421:
createDirectory "docs"
createFile "/output.txt"
createDirectory "/docs"</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">SYSTEM(DIR="\docs") ! create argument if not existent, make it current
OPEN(FILE="output.txt", "NEW") ! in current directory
 
SYSTEM(DIR="C:\docs") ! create C:\docs if not existent, make it current
OPEN(FILE="output.txt", "NEW") ! in C:\docs </langsyntaxhighlight>
 
=={{header|i}}==
<langsyntaxhighlight lang="i">software {
create("output.txt")
create("docs/")
create("/output.txt")
create("/docs/")
}</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Icon does not support 'mkdir' - otherwise the Unicon code below will work. A work around would be to use 'system' to invoke command line to create a directory.
<langsyntaxhighlight Uniconlang="unicon">every dir := !["./","/"] do {
close(open(f := dir || "input.txt","w")) |stop("failure for open ",f)
mkdir(f := dir || "docs") |stop("failure for mkdir ",f)
}</langsyntaxhighlight>
Note: Icon and Unicon accept both / and \ for directory separators.
 
Line 1,009 ⟶ 1,450:
The conjunction <tt>!:</tt> with a scalar <tt>1</tt> to the left (<tt>1!:</tt>) provides the underlying cross-platform support for [http://www.jsoftware.com/help/dictionary/dx001.htm working with files].
 
<langsyntaxhighlight lang="j">'' 1!:2 <'/output.txt' NB. write an empty file
1!:5 <'/docs' NB. create a directory</langsyntaxhighlight>
 
However a number of libraries provide a more convenient/conventional interface to that underlying functionality.
<langsyntaxhighlight lang="j">require 'files'
NB. create two empty files named /output.txt and output.txt
'' fwrite '/output.txt' ; 'output.txt'
Line 1,019 ⟶ 1,460:
require 'general/dirutils' NB. addon package
NB. create two directories: /docs and docs:
dircreate '/docs' ; 'docs'</langsyntaxhighlight>
 
Finally note that writing a file in J creates that file. In typical use, files are referred to by name, and the entire contents of the file are written. (Appends and partial writes are also supported but they are more complicated than the typical case.)
Line 1,030 ⟶ 1,471:
 
=={{header|Java}}==
<syntaxhighlight lang ="java">import java.io.*;
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 {
public static void main(String args[]) {
Line 1,042 ⟶ 1,501:
}
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{works with|Node.js}}
<syntaxhighlight lang="javascript">const fs = require('fs');
 
function fct(err) {
if (err) console.log(err);
}
 
fs.writeFile("output.txt", "", fct);
fs.writeFile("/output.txt", "", fct);
 
fs.mkdir("docs", fct);
fs.mkdir("/docs", fct);</syntaxhighlight>
 
=={{header|JCL}}==
<syntaxhighlight lang="jcl">
<lang JCL>
// EXEC PGM=IEFBR14
//* CREATE EMPTY FILE NAMED "OUTPUT.TXT" (file names upper case only)
Line 1,051 ⟶ 1,524:
//* CREATE DIRECTORY (PARTITIONED DATA SET) NAMED "DOCS"
//ANYNAME DD UNIT=SYSDA,SPACE=(TRK,(1,1)),DSN=DOCS,DISP=(,CATLG)
</syntaxhighlight>
</lang>
 
=={{header|Julia}}==
<langsyntaxhighlight Julialang="julia"># many I/O functions have UNIX names
 
touch("output.txt")
Line 1,065 ⟶ 1,538:
catch e
warn(e)
end</langsyntaxhighlight>
 
=={{header|K}}==
Directory creation is OS-dependent
{{Works with|Kona}}
<langsyntaxhighlight Klang="k"> "output.txt" 1: ""
"/output.txt" 1: ""
\ mkdir docs
\ mkdir /docs</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">/* testing on Windows 10 which needs administrative privileges
to create files in the root */
 
Line 1,099 ⟶ 1,572:
println("$path already exists")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,120 ⟶ 1,593:
{{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}}==
<langsyntaxhighlight Lassolang="lasso">// create file
local(f) = file
handle => { #f->close }
Line 1,138 ⟶ 1,634:
// create directory in root file system (requires permissions at user OS level)
local(d = dir('//docs'))
#d->create</langsyntaxhighlight>
 
=={{header|LingoLFE}}==
 
<syntaxhighlight lang="lisp">
Create an empty file in cwd:
(: file write_file '"output.txt" '"Some data")
 
(: file make_dir '"docs")
<lang lingo>-- note: fileIO xtra is shipped with Director, i.e. an "internal"
(: file write_file '"/output.txt" '"Some data")
fp = xtra("fileIO").new()
(: file make_dir '"/docs")
fp.createFile("output.txt")</lang>
</syntaxhighlight>
 
Create empty file in root of current volume:
 
<lang lingo>-- note: fileIO xtra is shipped with Director, i.e. an "internal"
pd = the last char of _movie.path -- "\" for win, ":" for mac
_player.itemDelimiter = pd
vol = _movie.path.item[1]
fp = xtra("fileIO").new()
fp.createFile(vol&pd&"output.txt")</lang>
 
Creating an empty directory requires a 3rd party xtra, but there are various free xtras that allow this. Here as example usage of Shell xtra:
 
<lang lingo>shell_cmd("mkdir Docs") -- in cwd, both win and mac
shell_cmd("mkdir \Docs") -- win
shell_cmd("mkdir /Docs") -- mac</lang>
 
=={{header|Liberty BASIC}}==
Line 1,167 ⟶ 1,649:
<br>
Full pathnames including drive name and directory can be used- back-slash separated.
<syntaxhighlight lang="lb">
<lang lb>
nomainwin
 
Line 1,180 ⟶ 1,662:
 
end
</syntaxhighlight>
</lang>
 
=={{header|Lingo}}==
 
Create an empty file in cwd:
 
<syntaxhighlight lang="lingo">-- note: fileIO xtra is shipped with Director, i.e. an "internal"
fp = xtra("fileIO").new()
fp.createFile("output.txt")</syntaxhighlight>
 
Create empty file in root of current volume:
 
<syntaxhighlight lang="lingo">-- note: fileIO xtra is shipped with Director, i.e. an "internal"
pd = the last char of _movie.path -- "\" for win, ":" for mac
_player.itemDelimiter = pd
vol = _movie.path.item[1]
fp = xtra("fileIO").new()
fp.createFile(vol&pd&"output.txt")</syntaxhighlight>
 
Creating an empty directory requires a 3rd party xtra, but there are various free xtras that allow this. Here as example usage of Shell xtra:
 
<syntaxhighlight lang="lingo">shell_cmd("mkdir Docs") -- in cwd, both win and mac
shell_cmd("mkdir \Docs") -- win
shell_cmd("mkdir /Docs") -- mac</syntaxhighlight>
 
=={{header|Little}}==
We are going to use /tmp instead the root.
 
<langsyntaxhighlight Clang="c">void create_file(string path) {
FILE f;
unless (exists(path)) {
Line 1,213 ⟶ 1,719:
create_file("/tmp/output.txt");
create_dir("docs");
create_dir("/tmp/docs");</langsyntaxhighlight>
 
=={{header|LFE}}==
 
<lang lisp>
(: file write_file '"output.txt" '"Some data")
(: file make_dir '"docs")
(: file write_file '"/output.txt" '"Some data")
(: file make_dir '"/docs")
</lang>
 
=={{header|Lua}}==
Line 1,229 ⟶ 1,726:
==== Create File ====
 
<langsyntaxhighlight lang="lua">io.open("output.txt", "w"):close()
io.open("\\output.txt", "w"):close()</langsyntaxhighlight>
 
==== Create Directory ====
This solution sends the command to the OS shell.
 
<langsyntaxhighlight lang="lua">os.execute("mkdir docs")
os.execute("mkdir \\docs")</langsyntaxhighlight>
 
A more portable solution requires a library such as LuaFileSystem.
 
<langsyntaxhighlight lang="lua">require "lfs"
lfs.mkdir("docs")
lfs.mkdir("/docs")</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 1,261 ⟶ 1,758:
Work nice in Ubuntu using Wine.
 
In Windows 10 we have to open M2000 environment (m2000.exe) with elevated privileges to have write access directly in root directory (so without it, we get error from task(RootDir$))
Work nice in Windows 10 64bit. From explorer in C:\ we see directory docs but not file output.txt. File exist when we use M2000. Perhaps Explorer hide files;
 
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module MakeDirAndFile {
Def WorkingDir$, RootDir$
Line 1,284 ⟶ 1,781:
}
MakeDirAndFile
</syntaxhighlight>
</lang>
 
=={{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>
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">
<lang Maple>
FileTools:-Text:-WriteFile("output.txt", ""); # make empty file in current dir
FileTools:-MakeDirectory("docs"); # make empty dir in current dir
FileTools:-Text:-WriteFile("/output.txt", ""); # make empty file in root dir
FileTools:-MakeDirectory("/docs"); # make empty dir in root dir
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">
<lang Mathematica>
SetDirectory@NotebookDirectory[];
t = OpenWrite["output.txt"]
Line 1,308 ⟶ 1,859:
(*"left<>right" is shorthand for "StringJoin[left,right]"*)
 
</syntaxhighlight>
</lang>
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight Matlablang="matlab"> fid = fopen('output.txt','w'); fclose(fid);
fid = fopen('/output.txt','w'); fclose(fid);
mkdir('docs');
mkdir('/docs');</langsyntaxhighlight>
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">f: openw("/output.txt");
close(f);
 
Line 1,325 ⟶ 1,876:
/* Maxima has no function to create directories, but one can use the underlying Lisp system */
 
:lisp (mapcar #'ensure-directories-exist '("docs/" "/docs/"))</langsyntaxhighlight>
 
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">-- Here
f = createFile "output.txt"
close f
Line 1,336 ⟶ 1,886:
f = createFile "\output.txt"
close f
makeDir ("c:\docs")</langsyntaxhighlight>
 
=={{header|Mercury}}==
<langsyntaxhighlight lang="mercury">:- module create_file.
:- interface.
 
Line 1,384 ⟶ 1,934:
io.write_string(Stderr, io.error_message(Error), !IO),
io.nl(Stderr, !IO),
io.set_exit_status(1, !IO).</langsyntaxhighlight>
 
=={{header|Mirah}}==
<langsyntaxhighlight lang="mirah">import java.io.File
 
File.new('output.txt').createNewFile()
File.new('docs').mkdir()
File.new("docs#{File.separator}output.txt").createNewFile()
</syntaxhighlight>
</lang>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE FileCreation EXPORTS Main;
 
IMPORT FS, File, OSError, IO, Stdio;
Line 1,412 ⟶ 1,962:
| OSError.E => IO.Put("Error creating file or directory.\n", Stdio.stderr);
END;
END FileCreation.</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
<langsyntaxhighlight lang="nanoquery">import "Nanoquery.IO"
 
$f = new("File")
$f.create("output.txt")
$f.createDir("docs")
 
// in the root directory
$f.create("/output.txt")
$f.createDir("/docs")
</syntaxhighlight>
</lang>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.IO;
 
Line 1,449 ⟶ 1,999:
// no Exception for directory creation
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
 
Line 1,477 ⟶ 2,027:
 
return
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import os
 
open("output.txt", fmWrite).close()
Line 1,486 ⟶ 2,036:
 
open(DirSep & "output.txt", fmWrite).close()
createDir(DirSep & "docs")</langsyntaxhighlight>
 
{{trans|Python}}
<langsyntaxhighlight lang="nim">import os
const directories = ["/", "./"]
for directory in directories:
open(directory & "output.txt", fmWrite).close()
createDir(directory & "docs")</langsyntaxhighlight>
 
=={{header|Objective-C}}==
 
<lang objc>NSFileManager *fm = [NSFileManager defaultManager];
 
[fm createFileAtPath:@"output.txt" contents:[NSData data] attributes:nil];
// Pre-OS X 10.5
[fm createDirectoryAtPath:@"docs" attributes:nil];
// OS X 10.5+
[fm createDirectoryAtPath:@"docs" withIntermediateDirectories:NO attributes:nil error:NULL];</lang>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang=" objeck">
use IO;
 
Line 1,523 ⟶ 2,063:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Objective-C}}==
 
<syntaxhighlight lang="objc">NSFileManager *fm = [NSFileManager defaultManager];
 
[fm createFileAtPath:@"output.txt" contents:[NSData data] attributes:nil];
// Pre-OS X 10.5
[fm createDirectoryAtPath:@"docs" attributes:nil];
// OS X 10.5+
[fm createDirectoryAtPath:@"docs" withIntermediateDirectories:NO attributes:nil error:NULL];</syntaxhighlight>
 
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml"># let oc = open_out "output.txt" in
close_out oc;;
- : unit = ()
 
# Unix.mkdir "docs" 0o750 ;; (* rights 0o750 for rwxr-x--- *)
- : unit = ()</langsyntaxhighlight>
 
(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">for Dir in ["/" "./"] do
File = {New Open.file init(name:Dir#"output.txt" flags:[create])}
in
{File close}
{OS.mkDir Dir#"docs" ['S_IRUSR' 'S_IWUSR' 'S_IXUSR' 'S_IXGRP']}
end</langsyntaxhighlight>
 
 
=={{header|PARI/GP}}==
Creating an empty file in GP requires <code>write1</code> rather than <code>write</code> to avoid the automatic newline.
<langsyntaxhighlight lang="parigp">write1("0.txt","")
write1("/0.txt","")</langsyntaxhighlight>
 
GP cannot, itself, create directories; for that, you would need PARI (where the solution would follow those in [[#C|C]]) or <code>system</code>:
<langsyntaxhighlight lang="parigp">system("mkdir newdir")</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 1,557 ⟶ 2,106:
The Pascal & Delphi Standard Libraries support all of this functionality.
 
<langsyntaxhighlight lang="pascal-delphi">
program in out;
 
Line 1,575 ⟶ 2,124:
 
end;
</syntaxhighlight>
</lang>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use File::Spec::Functions qw(catfile rootdir);
{ # here
open my $fh, '>', 'output.txt';
Line 1,586 ⟶ 2,135:
open my $fh, '>', catfile rootdir, 'output.txt';
mkdir catfile rootdir, 'docs';
};</langsyntaxhighlight>
 
'''Without Perl Modules'''
 
Current directory
<langsyntaxhighlight lang="perl">perl -e 'qx(touch output.txt)'
perl -e 'mkdir docs'</langsyntaxhighlight>
 
Root directory
<langsyntaxhighlight lang="perl">perl -e 'qx(touch /output.txt)'
perl -e 'mkdir "/docs"'</langsyntaxhighlight>
 
'''For comparison with Perl 6Raku'''
<langsyntaxhighlight lang="perl">for my $prefix (qw( ./ / )) {
mkdir "${prefix}docs";
open my $FH, '>', "${prefix}docs/output.txt";
}</langsyntaxhighlight>
Cleanup
<langsyntaxhighlight lang="perl">unlink $_ for qw(/docs/output.txt ./docs/output.txt);
rmdir $_ for qw(/docs ./docs);</langsyntaxhighlight>
 
=={{header|Perl 6}}==
<lang perl6>
for '.', '' -> $prefix {
mkdir "$prefix/docs";
open "$prefix/output.txt", :w;
}
</lang>
 
=={{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">(phixonline)-->
<lang Phix>integer fn
<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</lang>
<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}}==
<langsyntaxhighlight lang="php"><?php
touch('output.txt');
mkdir('docs');
touch('/output.txt');
mkdir('/docs');
?></langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(out "output.txt") # Empty output
(call 'mkdir "docs") # Call external
(out "/output.txt")
(call 'mkdir "/docs")</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">import Stdio;
 
int main(){
write_file("input.txt","",0100);
write_file("/input.txt","",0100);
}</langsyntaxhighlight>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
open file (output) title ('/OUTPUT.TXT,type(text),recsize(100)' );
close file (output);
</syntaxhighlight>
</lang>
 
=={{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>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">New-Item output.txt -ItemType File
New-Item \output.txt -ItemType File
New-Item docs -ItemType Directory
New-Item \docs -ItemType Directory</langsyntaxhighlight>
 
=={{header|ProDOS}}==
<langsyntaxhighlight ProDOSlang="prodos">makedirectory docs
changedirectory docs
makenewfile output.txt</langsyntaxhighlight>
 
=={{header|PureBasic}}==
 
<langsyntaxhighlight PureBasiclang="purebasic">CreateFile(0,"output.txt"):CloseFile(0)
CreateDirectory("docs")
CreateFile(0,"/output.txt"):CloseFile(0)
CreateDirectory("/docs")</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import os
for directory in ['/', './']:
open(directory + 'output.txt', 'w').close() # create /output.txt, then ./output.txt
os.mkdir(directory + 'docs') # create directory /docs, then ./docs</langsyntaxhighlight>
 
{{works with|Python|2.5}}
Exception-safe way to create file:
 
<langsyntaxhighlight lang="python">from __future__ import with_statement
import os
def create(directory):
Line 1,696 ⟶ 2,256:
create(".") # current directory
create("/") # root directory</langsyntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">f <- file("output.txt", "w")
close(f)
 
Line 1,708 ⟶ 2,268:
 
success <- dir.create("docs")
success <- dir.create("/docs")</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight Racketlang="racket">#lang racket
 
(display-to-file "" "output.txt")
(make-directory "docs")
(display-to-file "" "/output.txt")
(make-directory "/docs")</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>
for '.', '' -> $prefix {
mkdir "$prefix/docs";
open "$prefix/output.txt", :w;
}
</syntaxhighlight>
 
=={{header|Raven}}==
 
<langsyntaxhighlight lang="raven">"" as str
str 'output.txt' write
str '/output.txt' write
'docs' mkdir
'/docs' mkdir</langsyntaxhighlight>
 
=={{header|REBOL}}==
 
<langsyntaxhighlight REBOLlang="rebol">; Creating in current directory:
 
write %output.txt ""
Line 1,737 ⟶ 2,306:
write %/output.txt ""
make-dir %/docs/
</syntaxhighlight>
</lang>
 
=={{header|Retro}}==
There are no facilities in Retro to create directories.
 
<syntaxhighlight lang="retro">
<lang Retro>with files'
"'output.txt" file:wW file:open file:close drop
"'/output.txt" file:wW file:open file:close drop</langsyntaxhighlight>
 
=={{header|REXX}}==
This REXX version works under Microsoft Windows (any version).
<langsyntaxhighlight lang="rexx">/*REXX pgm creates a new empty file and directory; in curr dir and root.*/
do 2 /*perform three statements twice.*/
'COPY NUL output.txt' /*copy a "null" (empty) file. */
Line 1,754 ⟶ 2,323:
'CD \' /*change currect dir to the root.*/
end /*2*/ /*now, go and perform them again.*/
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
 
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
system("mkdir C:\Ring\docs")
fopen("C:\Ring\docs\output.txt", "w+")
system("mkdir docs")
fopen("output.txt", "w+")
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">['/', './'].each{|dir|
Dir.mkdir(dir + 'docs') # create '/docs', then './docs'
File.open(dir + 'output.txt', 'w') {} # create empty file /output.txt, then ./output.txt
}</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight RunBasiclang="runbasic">open "output.txt" for output as #f
close #f
Line 1,778 ⟶ 2,347:
open "f:\doc\output.txt" for output as #f
close #f</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">use std::io::{self, Write};
use std::fs::{DirBuilder, File};
use std::path::Path;
Line 1,805 ⟶ 2,375:
let _ = writeln!(&mut io::stderr(), "Error: {}", error);
process::exit(code)
}</langsyntaxhighlight>
 
=={{header|S-BASIC}}==
CP/M (the only operating system supported by S-BASIC) does not have named directories or a
 
tree-structured file system. The closest thing to a "root" directory would be user area 0 on
 
drive A:, which on a stock system will be the logged in directory on a cold boot. The "call"
 
statement, which normally serves to invoke an assembly language routine, is here used to
 
call upon the BDOS to switch to the desired directory.
<syntaxhighlight lang="basic">
rem -- Set the logged drive ('A' to 'P')
procedure setdrive (drive = char)
var hl, de, bc, a_psw = integer
rem -- ensure drive letter is upper case
if drive >= 'a' then drive = drive - 32
hl = 0
de = drive - 65
bc = 0EH rem BDOS set drive function
a_psw = 0
rem - call BDOS with drive number in DE
call (5H,hl,de,bc,a_psw)
end
 
rem -- Set the CP/M user area (0 to 15)
procedure setuser (user = integer)
var hl, bc, a_psw = integer
hl = 0
bc = 20H rem BDOS set user function
a_psw = 0
rem - call BDOS with user number in DE
call (5H,hl,user,bc,a_psw)
end
 
comment
create empty file "output.txt" in current directory and in
startup directory (drive A:, user 0)
end
 
create "OUTPUT.TXT"
setdrive 'A'
setuser 0
create "OUTPUT.TXT"
 
end
</syntaxhighlight>
 
 
=={{header|Scala}}==
{{libheader|Scala}}<langsyntaxhighlight lang="scala">import java.io.File
 
object CreateFile extends App {
Line 1,819 ⟶ 2,437:
try { new File(s"${File.separator}docs").mkdir() }
catch { case e: Exception => println(s"Exception caught: $e with creating directory ${File.separator}docs") }
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(open-output-file "output.txt")
(open-output-file "/output.txt")</langsyntaxhighlight>
Results:
> file output.txt
Line 1,838 ⟶ 2,456:
when it is started by a normal user.
 
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "osfiles.s7i";
 
Line 1,851 ⟶ 2,469:
close(aFile);
mkdir("/docs");
end func;</langsyntaxhighlight>
 
Under Windows each filesystem has its own root.
Therefore you need to replace "/output.txt" and "/docs" with "/c/output.txt" and "/c/docs".
 
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">set the folder to "~/Desktop"
put "" into file "docs/output.txt"
set the folder to "/"
put empty into file "/docs/output.txt"</syntaxhighlight>
Or without defining a working directory:
<syntaxhighlight lang="sensetalk">put empty into file "~/Desktop/docs/output.txt"
put "" into file "/docs/output.txt"</syntaxhighlight>
Or using the Create command:
<syntaxhighlight lang="sensetalk">create file "output.txt"
create folder "docs"</syntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby"># Here
%f'output.txt' -> create;
%d'docs' -> create;
Line 1,863 ⟶ 2,493:
# Root dir
Dir.root + %f'output.txt' -> create;
Dir.root + %d'docs' -> create;</langsyntaxhighlight>
 
=={{header|Slate}}==
File creation locally:
<langsyntaxhighlight lang="slate">(File newNamed: 'output.txt') touch.
(Directory current / 'output.txt') touch.</langsyntaxhighlight>
 
File creation at root:
<langsyntaxhighlight lang="slate">(File newNamed: '/output.txt') touch.
(Directory root / 'output.txt') touch.</langsyntaxhighlight>
 
=={{header|Slope}}==
 
Local:
<syntaxhighlight lang="slate">(close (file-open-write "output.txt"))
(mkdir "docs" 0755)</syntaxhighlight>
 
Root:
<syntaxhighlight lang="slate">(close (file-open-write "/output.txt"))
(mkdir "/docs" 0755)</syntaxhighlight>
 
=={{header|Smalltalk}}==
Line 1,878 ⟶ 2,518:
[[Squeak]] has no notion of 'current directory' because it isn't tied to the shell that created it.
 
<langsyntaxhighlight lang="smalltalk">(FileDirectory on: 'c:\') newFileNamed: 'output.txt'; createDirectory: 'docs'.</langsyntaxhighlight>
 
In [[GNU Smalltalk]] you can do instead:
 
<langsyntaxhighlight lang="smalltalk">ws := (File name: 'output.txt') writeStream.
ws close.
Directory create: 'docs'.
Line 1,888 ⟶ 2,528:
ws := (File name: '/output.txt') writeStream.
ws close.
Directory create: '/docs'.</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
Line 1,895 ⟶ 2,535:
{{works with|CSnobol}}
 
<langsyntaxhighlight SNOBOL4lang="snobol4"> output(.file,1,'output.txt'); endfile(1) ;* Macro Spitbol
* output(.file,1,,'output.txt'); endfile(1) ;* CSnobol
host(1,'mkdir docs')
Line 1,902 ⟶ 2,542:
* output(.file,1,,'/output.txt'); endfile(1) ;* CSnobol
host(1,'mkdir /docs')
end</langsyntaxhighlight>
 
=={{header|SQLite}}==
<lang sqlite3>
/*
*Use '/' for *nix. Use whatever your root directory is on Windows.
*Must be run as admin.
*/
.shell mkdir "docs";
.shell mkdir "/docs";
.output output.txt
.output /output.txt
</lang>
 
=={{header|SQL PL}}==
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<langsyntaxhighlight lang="sql pl">
BEGIN
DECLARE UTL_FILE_HANDLER UTL_FILE.FILE_TYPE;
Line 1,944 ⟶ 2,572:
CALL UTL_FILE.FCLOSE(UTL_FILE_HANDLER);
END @
</syntaxhighlight>
</lang>
The current directory notion does not exist in Db2. However, we can consider the home directory of the instance (in this case db2inst1) as current.
For the directory under root, Db2 needs extra permissions to create a subdirectory at that level. Normally, that operation of creating a subdirectory at that level will raise an exception: "UTL_FILE.INVALID_OPERATION" SQLSTATE=58024.
Line 1,960 ⟶ 2,588:
output.txt
</pre>
 
=={{header|SQLite}}==
<syntaxhighlight lang="sqlite3">
/*
*Use '/' for *nix. Use whatever your root directory is on Windows.
*Must be run as admin.
*/
.shell mkdir "docs";
.shell mkdir "/docs";
.output output.txt
.output /output.txt
</syntaxhighlight>
 
=={{header|Standard ML}}==
 
<langsyntaxhighlight lang="sml">let val out = TextIO.openOut "output.txt" in
TextIO.closeOut out
end;
 
OS.FileSys.mkDir "docs";</langsyntaxhighlight>
 
(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
 
=={{header|Stata}}==
 
<lang stata>file open f using output.txt, write replace
See the [https://www.stata.com/help.cgi?file file] command in Stata documentation. Note that Stata has other ways to store files: [https://www.stata.com/help.cgi?save save] to store a dataset in .dta format, or the various [https://www.stata.com/help.cgi?export export] commands to store a dataset as CSV, Excl, SAS [http://support.sas.com/techsup/technote/ts140.pdf XPORT 5] or [http://support.sas.com/techsup/technote/ts140_2.pdf XPORT 8] or dBase format.
 
<syntaxhighlight lang="stata">file open f using output.txt, write replace
file close f
mkdir docs
Line 1,978 ⟶ 2,621:
file open f using \output.txt, write replace
file close f
mkdir \docs</langsyntaxhighlight>
 
=={{header|Tcl}}==
Line 1,984 ⟶ 2,627:
Assuming that we're supposed to create two files and two directories (one each here and one each in the file system root) and further assuming that the code is supposed to be portable, i.e. work on win, linux, MacOS (the task is really not clear):
 
<langsyntaxhighlight lang="tcl">close [open output.txt w]
close [open [file nativename /output.txt] w]
 
file mkdir docs
file mkdir [file nativename /docs]</langsyntaxhighlight>
 
=={{header|Toka}}==
 
<langsyntaxhighlight lang="toka">needs shell
" output.txt" "W" file.open file.close
" /output.txt" "W" file.open file.close
Line 1,998 ⟶ 2,641:
( Create the directories with permissions set to 777)
" docs" &777 mkdir
" /docs" &777 mkdir</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
- create file
Line 2,006 ⟶ 2,650:
- create directory
ERROR/STOP CREATE ("docs",project,-std-)
</syntaxhighlight>
</lang>
 
=={{header|UNIX Shell}}==
 
{{works with|Bourne Shell}}
<langsyntaxhighlight lang="bash">touch output.txt /output.txt # create both output.txt and /output.txt
mkdir /docs
mkdir docs # create both /docs and docs</langsyntaxhighlight>
 
{{works with|bash}}
<langsyntaxhighlight lang="bash">touch {/,}output.txt # create both /output.txt and output.txt
mkdir {/,}docs # create both /docs and docs</langsyntaxhighlight>
 
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have a filesystem, just namespaced variables. -->
Line 2,022 ⟶ 2,667:
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">decl file f
f.create "output.txt"
f.createdir "docs"
Line 2,029 ⟶ 2,674:
f.create "/output.txt"
f.createdir "/docs"
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Public Sub create_file()
Dim FileNumber As Integer
FileNumber = FreeFile
Line 2,040 ⟶ 2,686:
Open "C:\docs\output.txt" For Output As #FreeFile
Close #FreeFile
End Sub</langsyntaxhighlight>
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
Line 2,052 ⟶ 2,699:
objFSO.CreateFolder("\docs")
objFSO.CreateTextFile("\docs\output.txt")
</syntaxhighlight>
</lang>
 
=={{header|Vedit macro language}}==
When closing a file, Vedit saves it only if it has been modified. Therefore, in order to create an empty file, we first insert a character in the file and then delete it.
<langsyntaxhighlight lang="vedit">// In current directory
File_Open("input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close()
File_Mkdir("docs")
Line 2,062 ⟶ 2,709:
// In the root directory
File_Open("/input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close()
File_Mkdir("/docs")</langsyntaxhighlight>
 
=={{header|Visual Basic .NET}}==
Line 2,069 ⟶ 2,716:
 
{{works with|Visual Basic .NET|9.0+}}
<langsyntaxhighlight lang="vbnet"> 'Current Directory
IO.Directory.CreateDirectory("docs")
IO.File.Create("output.txt").Close()
Line 2,079 ⟶ 2,726:
'Root, platform independent
IO.Directory.CreateDirectory(IO.Path.DirectorySeparatorChar & "docs")
IO.File.Create(IO.Path.DirectorySeparatorChar & "output.txt").Close()</langsyntaxhighlight>
 
=={{header|Visual Objects}}==
//Use Library System Library
<syntaxhighlight lang="visualfoxpro">
DirMake(String2Psz("c:\docs"))
FCreate("c:\docs\output.txt", FC_NORMAL)
</syntaxhighlight>
 
{{omit from|SmileBASIC|Filesystem has no directories, only projects which cannot be manipulated by code.}}
 
=={{header|Wren}}==
To create a file in the root, assuming you have the necessary privileges, just change "output.txt"
to "/output.txt" in the following script.
 
Wren does not currently support the creation of directories.
<syntaxhighlight lang="wren">import "io" for File
 
// file is closed automatically after creation
File.create("output.txt") {}
 
// check size
System.print("%(File.size("output.txt")) bytes")</syntaxhighlight>
 
{{out}}
<pre>
0 bytes
</pre>
 
=={{header|X86 Assembly}}==
{{works with|NASM|Linux}}
<langsyntaxhighlight lang="asm">
; syscall numbers for readability. :]
 
Line 2,139 ⟶ 2,812:
int 0x80 ; Make kernel call
ret
</syntaxhighlight>
</lang>
 
=={{header|XPL0}}==
XPL0 does not currently create directories.
To create a file in the root directory, assuming you have permission,
insert a slash at the beginning, like this: /output.txt
 
<syntaxhighlight lang="xpl0">
int FD;
FD:= FOpen("output.txt", 1);
</syntaxhighlight>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">open "output.txt" for writing as #1
close #1
system("mkdir " + "f:\docs")
if open(2, "f:\docs\output.txt") then
print "Subdirectory or file already exists"
else
open "f:\docs\output.txt" for writing as #2
close #2
end if</syntaxhighlight>
 
=={{header|zkl}}==
Works on Unix and Windows
<langsyntaxhighlight lang="zkl">$ ls -l docs
ls: cannot access docs: No such file or directory
$ zkl
Line 2,161 ⟶ 2,856:
total 0
-rw-r--r-- 1 craigd craigd 0 Oct 27 22:08 output.txt
</syntaxhighlight>
</lang>
 
=={{header|ZX Spectrum Basic}}==
Line 2,168 ⟶ 2,863:
we create an empty file named OUTPUT of zero bytes. We can use any start address, because the file is empty. Here we write zero bytes from address 16384:
 
<langsyntaxhighlight lang="zxbasic">SAVE "OUTPUT" CODE 16384,0</langsyntaxhighlight>
 
{{omit from|EasyLang}}
=={{header|Visual Objects}}==
//Use Library System Library
<lang visualfoxpro>
DirMake(String2Psz("c:\docs"))
FCreate("c:\docs\output.txt", FC_NORMAL)
</lang>
 
{{omit from|SmileBASIC|Filesystem has no directories, only projects which cannot be manipulated by code.}}
9,476

edits