Create a file: Difference between revisions

Content added Content deleted
No edit summary
m (syntax highlighting fixup automation)
Line 6: Line 6:
=={{header|11l}}==
=={{header|11l}}==
{{trans|Python}}
{{trans|Python}}
<lang 11l>L(directory) [‘/’, ‘./’]
<syntaxhighlight lang="11l">L(directory) [‘/’, ‘./’]
File(directory‘output.txt’, ‘w’) // create /output.txt, then ./output.txt
File(directory‘output.txt’, ‘w’) // create /output.txt, then ./output.txt
fs:create_dir(directory‘docs’) // create directory /docs, then ./docs</lang>
fs:create_dir(directory‘docs’) // create directory /docs, then ./docs</syntaxhighlight>


=={{header|4DOS Batch}}==
=={{header|4DOS Batch}}==
<lang 4dos>echos > output.txt
<syntaxhighlight lang="4dos">echos > output.txt
mkdir docs
mkdir docs


echos > \output.txt
echos > \output.txt
mkdir \docs</lang>
mkdir \docs</syntaxhighlight>


=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program createDirFic64.s */
/* program createDirFic64.s */
Line 130: Line 130:
.include "../includeARM64.inc"
.include "../includeARM64.inc"


</syntaxhighlight>
</lang>


=={{header|Action!}}==
=={{header|Action!}}==
The attached result has been obtained under DOS 2.5.
The attached result has been obtained under DOS 2.5.
<lang Action!>PROC Dir(CHAR ARRAY filter)
<syntaxhighlight lang="action!">PROC Dir(CHAR ARRAY filter)
CHAR ARRAY line(255)
CHAR ARRAY line(255)
BYTE dev=[1]
BYTE dev=[1]
Line 169: Line 169:
PrintF("Dir ""%S""%E",filter)
PrintF("Dir ""%S""%E",filter)
Dir(filter)
Dir(filter)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Create_a_file.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Create_a_file.png Screenshot from Atari 8-bit computer]
Line 191: Line 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>
* 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.
* The forward slash (/) notation works in Windows XP as well as Unix/Linux.
<lang ada>with Ada.Streams.Stream_IO, Ada.Directories;
<syntaxhighlight lang="ada">with Ada.Streams.Stream_IO, Ada.Directories;
use Ada.Streams.Stream_IO, Ada.Directories;
use Ada.Streams.Stream_IO, Ada.Directories;


Line 207: Line 207:
Create_Directory("/docs");
Create_Directory("/docs");
end File_Creation;</lang>
end File_Creation;</syntaxhighlight>


=={{header|Aikido}}==
=={{header|Aikido}}==
<lang aikido>
<syntaxhighlight lang="aikido">
var sout = openout ("output.txt") // in current dir
var sout = openout ("output.txt") // in current dir
sout.close()
sout.close()
Line 220: Line 220:
mkdir ("/docs")
mkdir ("/docs")


</syntaxhighlight>
</lang>


=={{header|Aime}}==
=={{header|Aime}}==
<lang aime># Make a directory using the -mkdir- program
<syntaxhighlight lang="aime"># Make a directory using the -mkdir- program
void
void
mkdir(text p)
mkdir(text p)
Line 259: Line 259:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Line 268: Line 268:
{{works with|ALGOL 68|Standard - no extensions to language used}}
{{works with|ALGOL 68|Standard - no extensions to language used}}
It may be best to to use an operating system provided library.
It may be best to to use an operating system provided library.
<lang algol68>main:(
<syntaxhighlight lang="algol68">main:(


INT errno;
INT errno;
Line 305: Line 305:


errno := mkpage("input.txt",2);
errno := mkpage("input.txt",2);
)</lang>
)</syntaxhighlight>


=={{header|APL}}==
=={{header|APL}}==
<lang APL> 'output.txt' ⎕ncreate ¯1+⌊/0,⎕nnums
<syntaxhighlight lang="apl"> 'output.txt' ⎕ncreate ¯1+⌊/0,⎕nnums
'\output.txt' ⎕ncreate ¯1+⌊/0,⎕nnums
'\output.txt' ⎕ncreate ¯1+⌊/0,⎕nnums
⎕mkdir 'Docs'
⎕mkdir 'Docs'
⎕mkdir '\Docs'</lang>
⎕mkdir '\Docs'</syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
Line 317: Line 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.
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.
<lang AppleScript >close (open for access "output.txt")</lang>
<syntaxhighlight lang="applescript ">close (open for access "output.txt")</syntaxhighlight>
Create a new folder (directory) on the startup disk (root directory).
Create a new folder (directory) on the startup disk (root directory).
<lang AppleScript >tell application "Finder" to make new folder at startup disk with properties {name:"docs"}</lang>
<syntaxhighlight lang="applescript ">tell application "Finder" to make new folder at startup disk with properties {name:"docs"}</syntaxhighlight>
Create a zero-byte text file in the frontmost (open) Finder window.
Create a zero-byte text file in the frontmost (open) Finder window.
<lang AppleScript >tell application "Finder" to set wd to target of window 1 as string
<syntaxhighlight lang="applescript ">tell application "Finder" to set wd to target of window 1 as string
close (open for access wd & "output.txt")</lang>
close (open for access wd & "output.txt")</syntaxhighlight>
Create a new folder (directory) in the frontmost (open) Finder window.
Create a new folder (directory) in the frontmost (open) Finder window.
<lang AppleScript >tell application "Finder" to make new folder at window 1 with properties {name:"docs"}</lang>
<syntaxhighlight lang="applescript ">tell application "Finder" to make new folder at window 1 with properties {name:"docs"}</syntaxhighlight>
--[[User:Apl.way|Apl.way]] 21:20, 9 June 2010 (UTC)
--[[User:Apl.way|Apl.way]] 21:20, 9 June 2010 (UTC)


Line 338: Line 338:
=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>


/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
Line 467: Line 467:


</syntaxhighlight>
</lang>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>output: "output.txt"
<syntaxhighlight lang="rebol">output: "output.txt"
docs: "docs"
docs: "docs"


Line 478: Line 478:


write join.path ["/" output] ""
write join.path ["/" output] ""
write.directory join.path ["/" docs] ø</lang>
write.directory join.path ["/" docs] ø</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>FileAppend,,output.txt
<syntaxhighlight lang="autohotkey">FileAppend,,output.txt
FileCreateDir, docs
FileCreateDir, docs
FileAppend,,c:\output.txt
FileAppend,,c:\output.txt
FileCreateDir, c:\docs</lang>
FileCreateDir, c:\docs</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<lang awk>BEGIN {
<syntaxhighlight lang="awk">BEGIN {
printf "" > "output.txt"
printf "" > "output.txt"
close("output.txt")
close("output.txt")
Line 494: Line 494:
system("mkdir docs")
system("mkdir docs")
system("mkdir /docs")
system("mkdir /docs")
}</lang>
}</syntaxhighlight>


=={{header|Axe}}==
=={{header|Axe}}==
Since the TI-OS does not have a true filesystem, this task is emulated using an application variable instead of a file.
Since the TI-OS does not have a true filesystem, this task is emulated using an application variable instead of a file.
<lang axe>GetCalc("appvOUTPUT",0)</lang>
<syntaxhighlight lang="axe">GetCalc("appvOUTPUT",0)</syntaxhighlight>


=={{header|BASIC}}==
=={{header|BASIC}}==
<lang qbasic>OPEN "output.txt" FOR OUTPUT AS 1
<syntaxhighlight lang="qbasic">OPEN "output.txt" FOR OUTPUT AS 1
CLOSE
CLOSE
OPEN "\output.txt" FOR OUTPUT AS 1
OPEN "\output.txt" FOR OUTPUT AS 1
CLOSE</lang>
CLOSE</syntaxhighlight>


==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
There are disk volumes, but no folders in DOS 3.3.
There are disk volumes, but no folders in DOS 3.3.
<lang gwbasic> 0 D$ = CHR$ (4): PRINT D$"OPEN OUTPUT.TXT": PRINT D$"CLOSE"</lang>
<syntaxhighlight lang="gwbasic"> 0 D$ = CHR$ (4): PRINT D$"OPEN OUTPUT.TXT": PRINT D$"CLOSE"</syntaxhighlight>
==={{header|BaCon}}===
==={{header|BaCon}}===
<lang qbasic>' Create file and dir
<syntaxhighlight lang="qbasic">' Create file and dir
TRAP LOCAL
TRAP LOCAL


Line 532: Line 532:


LABEL report2
LABEL report2
PRINT ERR$(ERROR)</lang>
PRINT ERR$(ERROR)</syntaxhighlight>


{{out}}
{{out}}
Line 555: Line 555:
Even still, the empty file will still cause Commodore DOS to allocate 1 data block to the file, as reported in a directory listing.
Even still, the empty file will still cause Commodore DOS to allocate 1 data block to the file, as reported in a directory listing.


<lang gwbasic>
<syntaxhighlight lang="gwbasic">
10 rem create a file
10 rem create a file
20 open 10,8,10,"0:output.txt,seq,write"
20 open 10,8,10,"0:output.txt,seq,write"
Line 562: Line 562:
50 rem check device status for error
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
60 open 15,8,15:input#15,a,b$,c,d:print a;b$;c;d:close 15
</syntaxhighlight>
</lang>


<pre>
<pre>
Line 583: Line 583:


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>copy nul output.txt
<syntaxhighlight lang="dos">copy nul output.txt
copy nul \output.txt</lang>
copy nul \output.txt</syntaxhighlight>


<lang dos>md docs
<syntaxhighlight lang="dos">md docs
md \docs</lang>
md \docs</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> CLOSE #OPENOUT("output.txt")
<syntaxhighlight lang="bbcbasic"> CLOSE #OPENOUT("output.txt")
CLOSE #OPENOUT("\output.txt")
CLOSE #OPENOUT("\output.txt")
*MKDIR docs
*MKDIR docs
*MKDIR \docs</lang>
*MKDIR \docs</syntaxhighlight>


=={{header|Blue}}==
=={{header|Blue}}==
Line 600: Line 600:
Linux/x86-64. If you really want to create a file and dir in the root, prefix the paths with a slash.
Linux/x86-64. If you really want to create a file and dir in the root, prefix the paths with a slash.


<lang blue>global _start
<syntaxhighlight lang="blue">global _start


: syscall ( num:eax -- result:eax ) syscall ;
: syscall ( num:eax -- result:eax ) syscall ;
Line 633: Line 633:
make-docs-directory
make-docs-directory
bye
bye
;</lang>
;</syntaxhighlight>


=={{header|BQN}}==
=={{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>.
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>.


<lang bqn>"output.txt" •file.Chars ""
<syntaxhighlight lang="bqn">"output.txt" •file.Chars ""
"/output.txt" •file.Chars ""
"/output.txt" •file.Chars ""
•file.CreateDir "docs"
•file.CreateDir "docs"
•file.CreateDir "/docs"</lang>
•file.CreateDir "/docs"</syntaxhighlight>


=={{header|Bracmat}}==
=={{header|Bracmat}}==
<lang bracmat>put$(,"output.txt",NEW)</lang>
<syntaxhighlight lang="bracmat">put$(,"output.txt",NEW)</syntaxhighlight>
Or
Or
<lang bracmat>fil$("output.txt",w)</lang>
<syntaxhighlight lang="bracmat">fil$("output.txt",w)</syntaxhighlight>
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:
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:
<lang bracmat>fil$(,SET,-1)</lang>
<syntaxhighlight lang="bracmat">fil$(,SET,-1)</syntaxhighlight>
To create a directory we are dependent on the underlying OS. In DOS:
To create a directory we are dependent on the underlying OS. In DOS:
<lang bracmat>sys$"mkdir docs"</lang>
<syntaxhighlight lang="bracmat">sys$"mkdir docs"</syntaxhighlight>
And in the file system root:
And in the file system root:
<lang bracmat>sys$"mkdir \\docs"</lang>
<syntaxhighlight lang="bracmat">sys$"mkdir \\docs"</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
=== ISO C ===
=== ISO C ===
ISO C (directory creation not supported):
ISO C (directory creation not supported):
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


int main() {
int main() {
Line 664: Line 664:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=== POSIX ===
=== POSIX ===


{{works with|POSIX}}
{{works with|POSIX}}
<lang c>#include <sys/stat.h>
<syntaxhighlight lang="c">#include <sys/stat.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
Line 682: Line 682:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
Line 690: Line 690:
First, a solution with the C runtime functions <code>_creat</code> and <code>_mkdir</code>.
First, a solution with the C runtime functions <code>_creat</code> and <code>_mkdir</code>.


<lang c>#include <direct.h>
<syntaxhighlight lang="c">#include <direct.h>
#include <io.h>
#include <io.h>
#include <sys/stat.h>
#include <sys/stat.h>
Line 720: Line 720:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


Another solution with the kernel32 API functions <code>CreateFile</code> and <code>CreateDirectory</code>.
Another solution with the kernel32 API functions <code>CreateFile</code> and <code>CreateDirectory</code>.


<lang c>#include <windows.h>
<syntaxhighlight lang="c">#include <windows.h>
#include <stdio.h>
#include <stdio.h>


Line 755: Line 755:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=== OS/2 ===
=== OS/2 ===
Line 761: Line 761:
Using the OS/2 API functions <code>DosOpen</code> and <code>DosMkDir</code>.
Using the OS/2 API functions <code>DosOpen</code> and <code>DosMkDir</code>.


<lang c>#include <os2.h>
<syntaxhighlight lang="c">#include <os2.h>


int main(void) {
int main(void) {
Line 799: Line 799:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.IO;
using System.IO;


Line 814: Line 814:
Directory.CreateDirectory(@"\docs");
Directory.CreateDirectory(@"\docs");
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
Uses some Microsoft library:
Uses some Microsoft library:
<lang cpp>#include <direct.h>
<syntaxhighlight lang="cpp">#include <direct.h>
#include <fstream>
#include <fstream>


Line 831: Line 831:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


A cross-platform solution using C++17
A cross-platform solution using C++17


<lang cpp>#include <filesystem>
<syntaxhighlight lang="cpp">#include <filesystem>
#include <fstream>
#include <fstream>


Line 848: Line 848:
fs::create_directory("docs");
fs::create_directory("docs");
fs::create_directory("/docs");
fs::create_directory("/docs");
}</lang>
}</syntaxhighlight>


=={{header|ChucK}}==
=={{header|ChucK}}==
This creates a file in root:
This creates a file in root:
<syntaxhighlight lang="c">
<lang c>
FileIO text;
FileIO text;
text.open("output.txt", FileIO.WRITE);
text.open("output.txt", FileIO.WRITE);
</syntaxhighlight>
</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang lisp>(import '(java.io File))
<syntaxhighlight lang="lisp">(import '(java.io File))
(.createNewFile (new File "output.txt"))
(.createNewFile (new File "output.txt"))
(.mkdir (new File "docs"))
(.mkdir (new File "docs"))
(.createNewFile (File. (str (File/separator) "output.txt")))
(.createNewFile (File. (str (File/separator) "output.txt")))
(.mkdir (File. (str (File/separator) "docs")))</lang>
(.mkdir (File. (str (File/separator) "docs")))</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
{{works with|GnuCOBOL}} and other compilers with the system call extensions
{{works with|GnuCOBOL}} and other compilers with the system call extensions
<lang COBOL> identification division.
<syntaxhighlight lang="cobol"> identification division.
program-id. create-a-file.
program-id. create-a-file.


Line 906: Line 906:
.
.


end program create-a-file.</lang>
end program create-a-file.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 924: Line 924:


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Lisp provides open and close commands for I/O with files<lang lisp>(let ((stream (open "output.txt" :direction :output)))
Lisp provides open and close commands for I/O with files<syntaxhighlight lang="lisp">(let ((stream (open "output.txt" :direction :output)))
(close stream))</lang>
(close stream))</syntaxhighlight>
but it is more common to use ''with-open-file'' which has better exception handling.
but it is more common to use ''with-open-file'' which has better exception handling.
<lang lisp>(with-open-file (stream "output.txt" :direction :output)
<syntaxhighlight lang="lisp">(with-open-file (stream "output.txt" :direction :output)
;; use the stream here
;; use the stream here
)</lang>
)</syntaxhighlight>
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
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
<lang lisp>(let ((paths (list (make-pathname :directory '(:relative "docs"))
<syntaxhighlight lang="lisp">(let ((paths (list (make-pathname :directory '(:relative "docs"))
(make-pathname :directory '(:absolute "docs")))))
(make-pathname :directory '(:absolute "docs")))))
(mapcar #'ensure-directories-exist paths))</lang>
(mapcar #'ensure-directories-exist paths))</syntaxhighlight>
So creating a file called ''output.txt'' with an absolute path in the root directory becomes:
So creating a file called ''output.txt'' with an absolute path in the root directory becomes:
<lang lisp>(with-open-file
<syntaxhighlight lang="lisp">(with-open-file
(stream
(stream
(make-pathname :directory '(:absolute "") :name "output.txt")
(make-pathname :directory '(:absolute "") :name "output.txt")
:direction :output))</lang>
:direction :output))</syntaxhighlight>


On the other hand, if you may depend on the platform's pathname syntax then shorter notation may be used:
On the other hand, if you may depend on the platform's pathname syntax then shorter notation may be used:
<lang lisp>(mapcar #'ensure-directories-exist '(#p"docs/" #p"/docs/")))</lang>
<syntaxhighlight lang="lisp">(mapcar #'ensure-directories-exist '(#p"docs/" #p"/docs/")))</syntaxhighlight>


=={{header|Component Pascal}}==
=={{header|Component Pascal}}==
{{works with| BlackBox Component Builder}}
{{works with| BlackBox Component Builder}}
<lang oberon2>
<syntaxhighlight lang="oberon2">
MODULE CreateFile;
MODULE CreateFile;
IMPORT Files, StdLog;
IMPORT Files, StdLog;
Line 964: Line 964:


END CreateFile.
END CreateFile.
</syntaxhighlight>
</lang>


=={{header|Crystal}}==
=={{header|Crystal}}==
<lang ruby>File.write "output.txt", ""
<syntaxhighlight lang="ruby">File.write "output.txt", ""
Dir.mkdir "docs"
Dir.mkdir "docs"


File.write "/output.txt", ""
File.write "/output.txt", ""
Dir.mkdir "/docs"</lang>
Dir.mkdir "/docs"</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
For file creation, std.file.write function & std.stream.file class are used.<br>
For file creation, std.file.write function & std.stream.file class are used.<br>
For dir creation, std.file.mkdir is used.
For dir creation, std.file.mkdir is used.
<lang d>module fileio ;
<syntaxhighlight lang="d">module fileio ;
import std.stdio ;
import std.stdio ;
import std.path ;
import std.path ;
Line 1,021: Line 1,021:
writefln("== test: File & Dir Creation ==") ;
writefln("== test: File & Dir Creation ==") ;
testCreate("output.txt", "docs") ;
testCreate("output.txt", "docs") ;
}</lang>
}</syntaxhighlight>


=={{header|Dc}}==
=={{header|Dc}}==
<lang dc>! for d in . / ;do > "$d/output.txt" ; mkdir "$d/docs" ;done</lang>
<syntaxhighlight lang="dc">! for d in . / ;do > "$d/output.txt" ; mkdir "$d/docs" ;done</syntaxhighlight>


=={{header|DCL}}==
=={{header|DCL}}==
<lang DCL>open/write output_file output.txt
<syntaxhighlight lang="dcl">open/write output_file output.txt
open/write output_file [000000]output.txt
open/write output_file [000000]output.txt
create/directory [.docs]
create/directory [.docs]
create/directory [000000.docs]</lang>
create/directory [000000.docs]</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
Line 1,036: Line 1,036:
These functions illustrate two methods for creating text files in Delphi: standard text file I/O and filestreams.
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;
program createFile;


Line 1,139: Line 1,139:




</syntaxhighlight>
</lang>


=={{header|E}}==
=={{header|E}}==


<lang e><file:output.txt>.setBytes([])
<syntaxhighlight lang="e"><file:output.txt>.setBytes([])
<file:docs>.mkdir(null)
<file:docs>.mkdir(null)
<file:///output.txt>.setBytes([])
<file:///output.txt>.setBytes([])
<file:///docs>.mkdir(null)</lang>
<file:///docs>.mkdir(null)</syntaxhighlight>


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<lang lisp>
<syntaxhighlight lang="lisp">
;; The file system is the browser local storage
;; The file system is the browser local storage
;; It is divided into named stores (directories)
;; It is divided into named stores (directories)
Line 1,165: Line 1,165:
(local-stores 'root) → ("root" "root/docs")
(local-stores 'root) → ("root" "root/docs")
(local-stores 'user) → ("user" "user/docs")
(local-stores 'user) → ("user" "user/docs")
</syntaxhighlight>
</lang>


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 4.x :
ELENA 4.x :
<lang elena>import system'io;
<syntaxhighlight lang="elena">import system'io;
public program()
public program()
Line 1,180: Line 1,180:
Directory.assign("\docs").create();
Directory.assign("\docs").create();
}</lang>
}</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>File.open("output.txt", [:write])
<syntaxhighlight lang="elixir">File.open("output.txt", [:write])
File.open("/output.txt", [:write])
File.open("/output.txt", [:write])


File.mkdir!("docs")
File.mkdir!("docs")
File.mkdir!("/docs")</lang>
File.mkdir!("/docs")</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
<lang Lisp>(make-empty-file "output.txt")
<syntaxhighlight lang="lisp">(make-empty-file "output.txt")
(make-directory "docs")
(make-directory "docs")
(make-empty-file "/output.txt")
(make-empty-file "/output.txt")
(make-directory "/docs")</lang>
(make-directory "/docs")</syntaxhighlight>


=={{header|Erlang}}==
=={{header|Erlang}}==
"/" is documented as working on Windows.
"/" is documented as working on Windows.
<lang erlang>
<syntaxhighlight lang="erlang">
-module(new_file).
-module(new_file).
-export([main/0]).
-export([main/0]).
Line 1,206: Line 1,206:
ok = file:write_file( filename:join(["/", "output.txt"]), <<>> ),
ok = file:write_file( filename:join(["/", "output.txt"]), <<>> ),
ok = file:make_dir( filename:join(["/", "docs"]) ).
ok = file:make_dir( filename:join(["/", "docs"]) ).
</syntaxhighlight>
</lang>


=={{header|ERRE}}==
=={{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.
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.
You must use PC.LIB for managing directories.
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM FILE_TEST
PROGRAM FILE_TEST


Line 1,226: Line 1,226:


END PROGRAM
END PROGRAM
</syntaxhighlight>
</lang>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<lang euphroria>integer fn
<syntaxhighlight lang="euphroria">integer fn


-- In the current working directory
-- In the current working directory
Line 1,239: Line 1,239:
system("mkdir \\docs",2)
system("mkdir \\docs",2)
fn = open("\\output.txt","w")
fn = open("\\output.txt","w")
close(fn)</lang>
close(fn)</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>open System.IO
<syntaxhighlight lang="fsharp">open System.IO
[<EntryPoint>]
[<EntryPoint>]
Line 1,251: Line 1,251:
ignore (File.Create(Path.Combine(path, fileName)))
ignore (File.Create(Path.Combine(path, fileName)))
ignore (Directory.CreateDirectory(Path.Combine(path, dirName)))
ignore (Directory.CreateDirectory(Path.Combine(path, dirName)))
0</lang>
0</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USE: io.directories
<syntaxhighlight lang="factor">USE: io.directories


"output.txt" "/output.txt" [ touch-file ] bi@
"output.txt" "/output.txt" [ touch-file ] bi@
"docs" "/docs" [ make-directory ] bi@</lang>
"docs" "/docs" [ make-directory ] bi@</syntaxhighlight>


=={{header|Fancy}}==
=={{header|Fancy}}==
<lang fancy>["/", "./"] each: |dir| {
<syntaxhighlight lang="fancy">["/", "./"] each: |dir| {
# create '/docs', then './docs'
# create '/docs', then './docs'
Directory create: (dir ++ "docs")
Directory create: (dir ++ "docs")
Line 1,267: Line 1,267:
f writeln: "hello, world!"
f writeln: "hello, world!"
}
}
}</lang>
}</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
There is no means to create directories in ANS Forth.
There is no means to create directories in ANS Forth.
<lang forth> s" output.txt" w/o create-file throw ( fileid) drop
<syntaxhighlight lang="forth"> s" output.txt" w/o create-file throw ( fileid) drop
s" /output.txt" w/o create-file throw ( fileid) drop</lang>
s" /output.txt" w/o create-file throw ( fileid) drop</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
Line 1,278: Line 1,278:
Don't know a way of creating directories in Fortran
Don't know a way of creating directories in Fortran
#Edit: Use system commands to create directories
#Edit: Use system commands to create directories
<lang fortran>
<syntaxhighlight lang="fortran">
PROGRAM CREATION
PROGRAM CREATION
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW") ! Current directory
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW") ! Current directory
Line 1,291: Line 1,291:


END PROGRAM
END PROGRAM
</syntaxhighlight>
</lang>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


' create empty file and sub-directory in current directory
' create empty file and sub-directory in current directory
Line 1,308: Line 1,308:


Print "Press any key to quit"
Print "Press any key to quit"
Sleep</lang>
Sleep</syntaxhighlight>


=={{header|friendly interactive shell}}==
=={{header|friendly interactive shell}}==
{{trans|UNIX Shell}}
{{trans|UNIX Shell}}
<lang fishshell>touch {/,}output.txt # create both /output.txt and output.txt
<syntaxhighlight lang="fishshell">touch {/,}output.txt # create both /output.txt and output.txt
mkdir {/,}docs # create both /docs and docs</lang>
mkdir {/,}docs # create both /docs and docs</syntaxhighlight>


=={{header|FunL}}==
=={{header|FunL}}==
{{trans|Scala}}
{{trans|Scala}}
<lang funl>import io.File
<syntaxhighlight lang="funl">import io.File


File( 'output.txt' ).createNewFile()
File( 'output.txt' ).createNewFile()
File( File.separator + 'output.txt' ).createNewFile()
File( File.separator + 'output.txt' ).createNewFile()
File( 'docs' ).mkdir()
File( 'docs' ).mkdir()
File( File.separator + 'docs' ).mkdir()</lang>
File( File.separator + 'docs' ).mkdir()</syntaxhighlight>


=={{header|Gambas}}==
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=abe59d5d62a4d01817638115e75e7e29 Click this link to run this code]'''
'''[https://gambas-playground.proko.eu/?gist=abe59d5d62a4d01817638115e75e7e29 Click this link to run this code]'''
<lang gambas>Public Sub Main()
<syntaxhighlight lang="gambas">Public Sub Main()
Dim byCount As Byte
Dim byCount As Byte
Dim sToSave As String
Dim sToSave As String
Line 1,337: Line 1,337:
Print File.Load(User.Home &/ "TestFile")
Print File.Load(User.Home &/ "TestFile")


End</lang>
End</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 1,349: Line 1,349:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,380: Line 1,380:
createDir("docs")
createDir("docs")
createDir("/docs")
createDir("/docs")
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>new File("output.txt").createNewFile()
<syntaxhighlight lang="groovy">new File("output.txt").createNewFile()
new File(File.separator + "output.txt").createNewFile()
new File(File.separator + "output.txt").createNewFile()
new File("docs").mkdir()
new File("docs").mkdir()
new File(File.separator + "docs").mkdir()</lang>
new File(File.separator + "docs").mkdir()</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==


<lang haskell>import System.Directory
<syntaxhighlight lang="haskell">import System.Directory


createFile name = writeFile name ""
createFile name = writeFile name ""
Line 1,398: Line 1,398:
createDirectory "docs"
createDirectory "docs"
createFile "/output.txt"
createFile "/output.txt"
createDirectory "/docs"</lang>
createDirectory "/docs"</syntaxhighlight>


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang hicest>SYSTEM(DIR="\docs") ! create argument if not existent, make it current
<syntaxhighlight lang="hicest">SYSTEM(DIR="\docs") ! create argument if not existent, make it current
OPEN(FILE="output.txt", "NEW") ! in current directory
OPEN(FILE="output.txt", "NEW") ! in current directory


SYSTEM(DIR="C:\docs") ! create C:\docs if not existent, make it current
SYSTEM(DIR="C:\docs") ! create C:\docs if not existent, make it current
OPEN(FILE="output.txt", "NEW") ! in C:\docs </lang>
OPEN(FILE="output.txt", "NEW") ! in C:\docs </syntaxhighlight>


=={{header|i}}==
=={{header|i}}==
<lang i>software {
<syntaxhighlight lang="i">software {
create("output.txt")
create("output.txt")
create("docs/")
create("docs/")
create("/output.txt")
create("/output.txt")
create("/docs/")
create("/docs/")
}</lang>
}</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{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.
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.
<lang Unicon>every dir := !["./","/"] do {
<syntaxhighlight lang="unicon">every dir := !["./","/"] do {
close(open(f := dir || "input.txt","w")) |stop("failure for open ",f)
close(open(f := dir || "input.txt","w")) |stop("failure for open ",f)
mkdir(f := dir || "docs") |stop("failure for mkdir ",f)
mkdir(f := dir || "docs") |stop("failure for mkdir ",f)
}</lang>
}</syntaxhighlight>
Note: Icon and Unicon accept both / and \ for directory separators.
Note: Icon and Unicon accept both / and \ for directory separators.


Line 1,427: Line 1,427:
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].
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].


<lang j>'' 1!:2 <'/output.txt' NB. write an empty file
<syntaxhighlight lang="j">'' 1!:2 <'/output.txt' NB. write an empty file
1!:5 <'/docs' NB. create a directory</lang>
1!:5 <'/docs' NB. create a directory</syntaxhighlight>


However a number of libraries provide a more convenient/conventional interface to that underlying functionality.
However a number of libraries provide a more convenient/conventional interface to that underlying functionality.
<lang j>require 'files'
<syntaxhighlight lang="j">require 'files'
NB. create two empty files named /output.txt and output.txt
NB. create two empty files named /output.txt and output.txt
'' fwrite '/output.txt' ; 'output.txt'
'' fwrite '/output.txt' ; 'output.txt'
Line 1,437: Line 1,437:
require 'general/dirutils' NB. addon package
require 'general/dirutils' NB. addon package
NB. create two directories: /docs and docs:
NB. create two directories: /docs and docs:
dircreate '/docs' ; 'docs'</lang>
dircreate '/docs' ; 'docs'</syntaxhighlight>


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.)
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,448: Line 1,448:


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.io.*;
<syntaxhighlight lang="java">import java.io.*;
public class CreateFileTest {
public class CreateFileTest {
public static void main(String args[]) {
public static void main(String args[]) {
Line 1,460: Line 1,460:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
{{works with|Node.js}}
{{works with|Node.js}}
<lang javascript>const fs = require('fs');
<syntaxhighlight lang="javascript">const fs = require('fs');


function fct(err) {
function fct(err) {
Line 1,474: Line 1,474:


fs.mkdir("docs", fct);
fs.mkdir("docs", fct);
fs.mkdir("/docs", fct);</lang>
fs.mkdir("/docs", fct);</syntaxhighlight>


=={{header|JCL}}==
=={{header|JCL}}==
<syntaxhighlight lang="jcl">
<lang JCL>
// EXEC PGM=IEFBR14
// EXEC PGM=IEFBR14
//* CREATE EMPTY FILE NAMED "OUTPUT.TXT" (file names upper case only)
//* CREATE EMPTY FILE NAMED "OUTPUT.TXT" (file names upper case only)
Line 1,483: Line 1,483:
//* CREATE DIRECTORY (PARTITIONED DATA SET) NAMED "DOCS"
//* CREATE DIRECTORY (PARTITIONED DATA SET) NAMED "DOCS"
//ANYNAME DD UNIT=SYSDA,SPACE=(TRK,(1,1)),DSN=DOCS,DISP=(,CATLG)
//ANYNAME DD UNIT=SYSDA,SPACE=(TRK,(1,1)),DSN=DOCS,DISP=(,CATLG)
</syntaxhighlight>
</lang>


=={{header|Julia}}==
=={{header|Julia}}==
<lang Julia># many I/O functions have UNIX names
<syntaxhighlight lang="julia"># many I/O functions have UNIX names


touch("output.txt")
touch("output.txt")
Line 1,497: Line 1,497:
catch e
catch e
warn(e)
warn(e)
end</lang>
end</syntaxhighlight>


=={{header|K}}==
=={{header|K}}==
Directory creation is OS-dependent
Directory creation is OS-dependent
{{Works with|Kona}}
{{Works with|Kona}}
<lang K> "output.txt" 1: ""
<syntaxhighlight lang="k"> "output.txt" 1: ""
"/output.txt" 1: ""
"/output.txt" 1: ""
\ mkdir docs
\ mkdir docs
\ mkdir /docs</lang>
\ mkdir /docs</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>/* testing on Windows 10 which needs administrative privileges
<syntaxhighlight lang="scala">/* testing on Windows 10 which needs administrative privileges
to create files in the root */
to create files in the root */


Line 1,531: Line 1,531:
println("$path already exists")
println("$path already exists")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,553: Line 1,553:


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>// create file
<syntaxhighlight lang="lasso">// create file
local(f) = file
local(f) = file
handle => { #f->close }
handle => { #f->close }
Line 1,569: Line 1,569:
// create directory in root file system (requires permissions at user OS level)
// create directory in root file system (requires permissions at user OS level)
local(d = dir('//docs'))
local(d = dir('//docs'))
#d->create</lang>
#d->create</syntaxhighlight>


=={{header|LFE}}==
=={{header|LFE}}==


<lang lisp>
<syntaxhighlight lang="lisp">
(: file write_file '"output.txt" '"Some data")
(: file write_file '"output.txt" '"Some data")
(: file make_dir '"docs")
(: file make_dir '"docs")
(: file write_file '"/output.txt" '"Some data")
(: file write_file '"/output.txt" '"Some data")
(: file make_dir '"/docs")
(: file make_dir '"/docs")
</syntaxhighlight>
</lang>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
Line 1,584: Line 1,584:
<br>
<br>
Full pathnames including drive name and directory can be used- back-slash separated.
Full pathnames including drive name and directory can be used- back-slash separated.
<syntaxhighlight lang="lb">
<lang lb>
nomainwin
nomainwin


Line 1,597: Line 1,597:


end
end
</syntaxhighlight>
</lang>


=={{header|Lingo}}==
=={{header|Lingo}}==
Line 1,603: Line 1,603:
Create an empty file in cwd:
Create an empty file in cwd:


<lang lingo>-- note: fileIO xtra is shipped with Director, i.e. an "internal"
<syntaxhighlight lang="lingo">-- note: fileIO xtra is shipped with Director, i.e. an "internal"
fp = xtra("fileIO").new()
fp = xtra("fileIO").new()
fp.createFile("output.txt")</lang>
fp.createFile("output.txt")</syntaxhighlight>


Create empty file in root of current volume:
Create empty file in root of current volume:


<lang lingo>-- note: fileIO xtra is shipped with Director, i.e. an "internal"
<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
pd = the last char of _movie.path -- "\" for win, ":" for mac
_player.itemDelimiter = pd
_player.itemDelimiter = pd
vol = _movie.path.item[1]
vol = _movie.path.item[1]
fp = xtra("fileIO").new()
fp = xtra("fileIO").new()
fp.createFile(vol&pd&"output.txt")</lang>
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:
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
<syntaxhighlight lang="lingo">shell_cmd("mkdir Docs") -- in cwd, both win and mac
shell_cmd("mkdir \Docs") -- win
shell_cmd("mkdir \Docs") -- win
shell_cmd("mkdir /Docs") -- mac</lang>
shell_cmd("mkdir /Docs") -- mac</syntaxhighlight>


=={{header|Little}}==
=={{header|Little}}==
We are going to use /tmp instead the root.
We are going to use /tmp instead the root.


<lang C>void create_file(string path) {
<syntaxhighlight lang="c">void create_file(string path) {
FILE f;
FILE f;
unless (exists(path)) {
unless (exists(path)) {
Line 1,654: Line 1,654:
create_file("/tmp/output.txt");
create_file("/tmp/output.txt");
create_dir("docs");
create_dir("docs");
create_dir("/tmp/docs");</lang>
create_dir("/tmp/docs");</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
Line 1,661: Line 1,661:
==== Create File ====
==== Create File ====


<lang lua>io.open("output.txt", "w"):close()
<syntaxhighlight lang="lua">io.open("output.txt", "w"):close()
io.open("\\output.txt", "w"):close()</lang>
io.open("\\output.txt", "w"):close()</syntaxhighlight>


==== Create Directory ====
==== Create Directory ====
This solution sends the command to the OS shell.
This solution sends the command to the OS shell.


<lang lua>os.execute("mkdir docs")
<syntaxhighlight lang="lua">os.execute("mkdir docs")
os.execute("mkdir \\docs")</lang>
os.execute("mkdir \\docs")</syntaxhighlight>


A more portable solution requires a library such as LuaFileSystem.
A more portable solution requires a library such as LuaFileSystem.


<lang lua>require "lfs"
<syntaxhighlight lang="lua">require "lfs"
lfs.mkdir("docs")
lfs.mkdir("docs")
lfs.mkdir("/docs")</lang>
lfs.mkdir("/docs")</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
Line 1,696: Line 1,696:




<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module MakeDirAndFile {
Module MakeDirAndFile {
Def WorkingDir$, RootDir$
Def WorkingDir$, RootDir$
Line 1,716: Line 1,716:
}
}
MakeDirAndFile
MakeDirAndFile
</syntaxhighlight>
</lang>


=={{header|Maple}}==
=={{header|Maple}}==
<syntaxhighlight lang="maple">
<lang Maple>
FileTools:-Text:-WriteFile("output.txt", ""); # make empty file in current dir
FileTools:-Text:-WriteFile("output.txt", ""); # make empty file in current dir
FileTools:-MakeDirectory("docs"); # make empty dir in current dir
FileTools:-MakeDirectory("docs"); # make empty dir in current dir
FileTools:-Text:-WriteFile("/output.txt", ""); # make empty file in root dir
FileTools:-Text:-WriteFile("/output.txt", ""); # make empty file in root dir
FileTools:-MakeDirectory("/docs"); # make empty dir in root dir
FileTools:-MakeDirectory("/docs"); # make empty dir in root dir
</syntaxhighlight>
</lang>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">
<lang Mathematica>
SetDirectory@NotebookDirectory[];
SetDirectory@NotebookDirectory[];
t = OpenWrite["output.txt"]
t = OpenWrite["output.txt"]
Line 1,740: Line 1,740:
(*"left<>right" is shorthand for "StringJoin[left,right]"*)
(*"left<>right" is shorthand for "StringJoin[left,right]"*)


</syntaxhighlight>
</lang>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
<lang Matlab> fid = fopen('output.txt','w'); fclose(fid);
<syntaxhighlight lang="matlab"> fid = fopen('output.txt','w'); fclose(fid);
fid = fopen('/output.txt','w'); fclose(fid);
fid = fopen('/output.txt','w'); fclose(fid);
mkdir('docs');
mkdir('docs');
mkdir('/docs');</lang>
mkdir('/docs');</syntaxhighlight>


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>f: openw("/output.txt");
<syntaxhighlight lang="maxima">f: openw("/output.txt");
close(f);
close(f);


Line 1,757: Line 1,757:
/* Maxima has no function to create directories, but one can use the underlying Lisp system */
/* Maxima has no function to create directories, but one can use the underlying Lisp system */


:lisp (mapcar #'ensure-directories-exist '("docs/" "/docs/"))</lang>
:lisp (mapcar #'ensure-directories-exist '("docs/" "/docs/"))</syntaxhighlight>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
<lang maxscript>-- Here
<syntaxhighlight lang="maxscript">-- Here
f = createFile "output.txt"
f = createFile "output.txt"
close f
close f
Line 1,767: Line 1,767:
f = createFile "\output.txt"
f = createFile "\output.txt"
close f
close f
makeDir ("c:\docs")</lang>
makeDir ("c:\docs")</syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang mercury>:- module create_file.
<syntaxhighlight lang="mercury">:- module create_file.
:- interface.
:- interface.


Line 1,815: Line 1,815:
io.write_string(Stderr, io.error_message(Error), !IO),
io.write_string(Stderr, io.error_message(Error), !IO),
io.nl(Stderr, !IO),
io.nl(Stderr, !IO),
io.set_exit_status(1, !IO).</lang>
io.set_exit_status(1, !IO).</syntaxhighlight>


=={{header|Mirah}}==
=={{header|Mirah}}==
<lang mirah>import java.io.File
<syntaxhighlight lang="mirah">import java.io.File


File.new('output.txt').createNewFile()
File.new('output.txt').createNewFile()
File.new('docs').mkdir()
File.new('docs').mkdir()
File.new("docs#{File.separator}output.txt").createNewFile()
File.new("docs#{File.separator}output.txt").createNewFile()
</syntaxhighlight>
</lang>


=={{header|Modula-3}}==
=={{header|Modula-3}}==
<lang modula3>MODULE FileCreation EXPORTS Main;
<syntaxhighlight lang="modula3">MODULE FileCreation EXPORTS Main;


IMPORT FS, File, OSError, IO, Stdio;
IMPORT FS, File, OSError, IO, Stdio;
Line 1,843: Line 1,843:
| OSError.E => IO.Put("Error creating file or directory.\n", Stdio.stderr);
| OSError.E => IO.Put("Error creating file or directory.\n", Stdio.stderr);
END;
END;
END FileCreation.</lang>
END FileCreation.</syntaxhighlight>


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
<lang Nanoquery>import Nanoquery.IO
<syntaxhighlight lang="nanoquery">import Nanoquery.IO


f = new(File)
f = new(File)
Line 1,855: Line 1,855:
f.create("/output.txt")
f.create("/output.txt")
f.createDir("/docs")
f.createDir("/docs")
</syntaxhighlight>
</lang>


=={{header|Nemerle}}==
=={{header|Nemerle}}==
<lang Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.IO;
using System.IO;


Line 1,880: Line 1,880:
// no Exception for directory creation
// no Exception for directory creation
}
}
}</lang>
}</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
options replace format comments java crossref symbols nobinary


Line 1,908: Line 1,908:


return
return
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import os
<syntaxhighlight lang="nim">import os


open("output.txt", fmWrite).close()
open("output.txt", fmWrite).close()
Line 1,917: Line 1,917:


open(DirSep & "output.txt", fmWrite).close()
open(DirSep & "output.txt", fmWrite).close()
createDir(DirSep & "docs")</lang>
createDir(DirSep & "docs")</syntaxhighlight>


{{trans|Python}}
{{trans|Python}}
<lang nim>import os
<syntaxhighlight lang="nim">import os
const directories = ["/", "./"]
const directories = ["/", "./"]
for directory in directories:
for directory in directories:
open(directory & "output.txt", fmWrite).close()
open(directory & "output.txt", fmWrite).close()
createDir(directory & "docs")</lang>
createDir(directory & "docs")</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>
<syntaxhighlight lang=" objeck">
use IO;
use IO;


Line 1,944: Line 1,944:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Objective-C}}==
=={{header|Objective-C}}==


<lang objc>NSFileManager *fm = [NSFileManager defaultManager];
<syntaxhighlight lang="objc">NSFileManager *fm = [NSFileManager defaultManager];


[fm createFileAtPath:@"output.txt" contents:[NSData data] attributes:nil];
[fm createFileAtPath:@"output.txt" contents:[NSData data] attributes:nil];
Line 1,954: Line 1,954:
[fm createDirectoryAtPath:@"docs" attributes:nil];
[fm createDirectoryAtPath:@"docs" attributes:nil];
// OS X 10.5+
// OS X 10.5+
[fm createDirectoryAtPath:@"docs" withIntermediateDirectories:NO attributes:nil error:NULL];</lang>
[fm createDirectoryAtPath:@"docs" withIntermediateDirectories:NO attributes:nil error:NULL];</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==


<lang ocaml># let oc = open_out "output.txt" in
<syntaxhighlight lang="ocaml"># let oc = open_out "output.txt" in
close_out oc;;
close_out oc;;
- : unit = ()
- : unit = ()


# Unix.mkdir "docs" 0o750 ;; (* rights 0o750 for rwxr-x--- *)
# Unix.mkdir "docs" 0o750 ;; (* rights 0o750 for rwxr-x--- *)
- : unit = ()</lang>
- : unit = ()</syntaxhighlight>


(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")


=={{header|Oz}}==
=={{header|Oz}}==
<lang oz>for Dir in ["/" "./"] do
<syntaxhighlight lang="oz">for Dir in ["/" "./"] do
File = {New Open.file init(name:Dir#"output.txt" flags:[create])}
File = {New Open.file init(name:Dir#"output.txt" flags:[create])}
in
in
{File close}
{File close}
{OS.mkDir Dir#"docs" ['S_IRUSR' 'S_IWUSR' 'S_IXUSR' 'S_IXGRP']}
{OS.mkDir Dir#"docs" ['S_IRUSR' 'S_IWUSR' 'S_IXUSR' 'S_IXGRP']}
end</lang>
end</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
Creating an empty file in GP requires <code>write1</code> rather than <code>write</code> to avoid the automatic newline.
Creating an empty file in GP requires <code>write1</code> rather than <code>write</code> to avoid the automatic newline.
<lang parigp>write1("0.txt","")
<syntaxhighlight lang="parigp">write1("0.txt","")
write1("/0.txt","")</lang>
write1("/0.txt","")</syntaxhighlight>


GP cannot, itself, create directories; for that, you would need PARI (where the solution would follow those in [[#C|C]]) or <code>system</code>:
GP cannot, itself, create directories; for that, you would need PARI (where the solution would follow those in [[#C|C]]) or <code>system</code>:
<lang parigp>system("mkdir newdir")</lang>
<syntaxhighlight lang="parigp">system("mkdir newdir")</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 1,987: Line 1,987:
The Pascal & Delphi Standard Libraries support all of this functionality.
The Pascal & Delphi Standard Libraries support all of this functionality.


<lang pascal-delphi>
<syntaxhighlight lang="pascal-delphi">
program in out;
program in out;


Line 2,005: Line 2,005:


end;
end;
</syntaxhighlight>
</lang>


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>use File::Spec::Functions qw(catfile rootdir);
<syntaxhighlight lang="perl">use File::Spec::Functions qw(catfile rootdir);
{ # here
{ # here
open my $fh, '>', 'output.txt';
open my $fh, '>', 'output.txt';
Line 2,016: Line 2,016:
open my $fh, '>', catfile rootdir, 'output.txt';
open my $fh, '>', catfile rootdir, 'output.txt';
mkdir catfile rootdir, 'docs';
mkdir catfile rootdir, 'docs';
};</lang>
};</syntaxhighlight>


'''Without Perl Modules'''
'''Without Perl Modules'''


Current directory
Current directory
<lang perl>perl -e 'qx(touch output.txt)'
<syntaxhighlight lang="perl">perl -e 'qx(touch output.txt)'
perl -e 'mkdir docs'</lang>
perl -e 'mkdir docs'</syntaxhighlight>


Root directory
Root directory
<lang perl>perl -e 'qx(touch /output.txt)'
<syntaxhighlight lang="perl">perl -e 'qx(touch /output.txt)'
perl -e 'mkdir "/docs"'</lang>
perl -e 'mkdir "/docs"'</syntaxhighlight>


'''For comparison with Raku'''
'''For comparison with Raku'''
<lang perl>for my $prefix (qw( ./ / )) {
<syntaxhighlight lang="perl">for my $prefix (qw( ./ / )) {
mkdir "${prefix}docs";
mkdir "${prefix}docs";
open my $FH, '>', "${prefix}docs/output.txt";
open my $FH, '>', "${prefix}docs/output.txt";
}</lang>
}</syntaxhighlight>
Cleanup
Cleanup
<lang perl>unlink $_ for qw(/docs/output.txt ./docs/output.txt);
<syntaxhighlight lang="perl">unlink $_ for qw(/docs/output.txt ./docs/output.txt);
rmdir $_ for qw(/docs ./docs);</lang>
rmdir $_ for qw(/docs ./docs);</syntaxhighlight>


=={{header|Phix}}==
=={{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)
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)
<lang Phix>integer fn
<syntaxhighlight lang="phix">integer fn
-- In the current working directory
-- In the current working directory
Line 2,053: Line 2,053:
else
else
close(fn)
close(fn)
end if</lang>
end if</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php
<syntaxhighlight lang="php"><?php
touch('output.txt');
touch('output.txt');
mkdir('docs');
mkdir('docs');
touch('/output.txt');
touch('/output.txt');
mkdir('/docs');
mkdir('/docs');
?></lang>
?></syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(out "output.txt") # Empty output
<syntaxhighlight lang="picolisp">(out "output.txt") # Empty output
(call 'mkdir "docs") # Call external
(call 'mkdir "docs") # Call external
(out "/output.txt")
(out "/output.txt")
(call 'mkdir "/docs")</lang>
(call 'mkdir "/docs")</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>import Stdio;
<syntaxhighlight lang="pike">import Stdio;


int main(){
int main(){
write_file("input.txt","",0100);
write_file("input.txt","",0100);
write_file("/input.txt","",0100);
write_file("/input.txt","",0100);
}</lang>
}</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
open file (output) title ('/OUTPUT.TXT,type(text),recsize(100)' );
open file (output) title ('/OUTPUT.TXT,type(text),recsize(100)' );
close file (output);
close file (output);
</syntaxhighlight>
</lang>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>New-Item output.txt -ItemType File
<syntaxhighlight lang="powershell">New-Item output.txt -ItemType File
New-Item \output.txt -ItemType File
New-Item \output.txt -ItemType File
New-Item docs -ItemType Directory
New-Item docs -ItemType Directory
New-Item \docs -ItemType Directory</lang>
New-Item \docs -ItemType Directory</syntaxhighlight>


=={{header|ProDOS}}==
=={{header|ProDOS}}==
<lang ProDOS>makedirectory docs
<syntaxhighlight lang="prodos">makedirectory docs
changedirectory docs
changedirectory docs
makenewfile output.txt</lang>
makenewfile output.txt</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==


<lang PureBasic>CreateFile(0,"output.txt"):CloseFile(0)
<syntaxhighlight lang="purebasic">CreateFile(0,"output.txt"):CloseFile(0)
CreateDirectory("docs")
CreateDirectory("docs")
CreateFile(0,"/output.txt"):CloseFile(0)
CreateFile(0,"/output.txt"):CloseFile(0)
CreateDirectory("/docs")</lang>
CreateDirectory("/docs")</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang python>import os
<syntaxhighlight lang="python">import os
for directory in ['/', './']:
for directory in ['/', './']:
open(directory + 'output.txt', 'w').close() # create /output.txt, then ./output.txt
open(directory + 'output.txt', 'w').close() # create /output.txt, then ./output.txt
os.mkdir(directory + 'docs') # create directory /docs, then ./docs</lang>
os.mkdir(directory + 'docs') # create directory /docs, then ./docs</syntaxhighlight>


{{works with|Python|2.5}}
{{works with|Python|2.5}}
Exception-safe way to create file:
Exception-safe way to create file:


<lang python>from __future__ import with_statement
<syntaxhighlight lang="python">from __future__ import with_statement
import os
import os
def create(directory):
def create(directory):
Line 2,118: Line 2,118:
create(".") # current directory
create(".") # current directory
create("/") # root directory</lang>
create("/") # root directory</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<lang R>f <- file("output.txt", "w")
<syntaxhighlight lang="r">f <- file("output.txt", "w")
close(f)
close(f)


Line 2,130: Line 2,130:


success <- dir.create("docs")
success <- dir.create("docs")
success <- dir.create("/docs")</lang>
success <- dir.create("/docs")</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
<lang Racket>#lang racket
<syntaxhighlight lang="racket">#lang racket


(display-to-file "" "output.txt")
(display-to-file "" "output.txt")
(make-directory "docs")
(make-directory "docs")
(display-to-file "" "/output.txt")
(display-to-file "" "/output.txt")
(make-directory "/docs")</lang>
(make-directory "/docs")</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<syntaxhighlight lang="raku" line>
<lang perl6>
for '.', '' -> $prefix {
for '.', '' -> $prefix {
mkdir "$prefix/docs";
mkdir "$prefix/docs";
open "$prefix/output.txt", :w;
open "$prefix/output.txt", :w;
}
}
</syntaxhighlight>
</lang>


=={{header|Raven}}==
=={{header|Raven}}==


<lang raven>"" as str
<syntaxhighlight lang="raven">"" as str
str 'output.txt' write
str 'output.txt' write
str '/output.txt' write
str '/output.txt' write
'docs' mkdir
'docs' mkdir
'/docs' mkdir</lang>
'/docs' mkdir</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==


<lang REBOL>; Creating in current directory:
<syntaxhighlight lang="rebol">; Creating in current directory:


write %output.txt ""
write %output.txt ""
Line 2,168: Line 2,168:
write %/output.txt ""
write %/output.txt ""
make-dir %/docs/
make-dir %/docs/
</syntaxhighlight>
</lang>


=={{header|Retro}}==
=={{header|Retro}}==
There are no facilities in Retro to create directories.
There are no facilities in Retro to create directories.


<syntaxhighlight lang="retro">
<lang Retro>
'output.txt file:W file:open file:close
'output.txt file:W file:open file:close
'/output.txt file:W file:open file:close</lang>
'/output.txt file:W file:open file:close</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
This REXX version works under Microsoft Windows (any version).
This REXX version works under Microsoft Windows (any version).
<lang rexx>/*REXX pgm creates a new empty file and directory; in curr dir and root.*/
<syntaxhighlight lang="rexx">/*REXX pgm creates a new empty file and directory; in curr dir and root.*/
do 2 /*perform three statements twice.*/
do 2 /*perform three statements twice.*/
'COPY NUL output.txt' /*copy a "null" (empty) file. */
'COPY NUL output.txt' /*copy a "null" (empty) file. */
Line 2,185: Line 2,185:
'CD \' /*change currect dir to the root.*/
'CD \' /*change currect dir to the root.*/
end /*2*/ /*now, go and perform them again.*/
end /*2*/ /*now, go and perform them again.*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
system("mkdir C:\Ring\docs")
system("mkdir C:\Ring\docs")
fopen("C:\Ring\docs\output.txt", "w+")
fopen("C:\Ring\docs\output.txt", "w+")
system("mkdir docs")
system("mkdir docs")
fopen("output.txt", "w+")
fopen("output.txt", "w+")
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>['/', './'].each{|dir|
<syntaxhighlight lang="ruby">['/', './'].each{|dir|
Dir.mkdir(dir + 'docs') # create '/docs', then './docs'
Dir.mkdir(dir + 'docs') # create '/docs', then './docs'
File.open(dir + 'output.txt', 'w') {} # create empty file /output.txt, then ./output.txt
File.open(dir + 'output.txt', 'w') {} # create empty file /output.txt, then ./output.txt
}</lang>
}</syntaxhighlight>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang RunBasic>open "output.txt" for output as #f
<syntaxhighlight lang="runbasic">open "output.txt" for output as #f
close #f
close #f
Line 2,209: Line 2,209:
open "f:\doc\output.txt" for output as #f
open "f:\doc\output.txt" for output as #f
close #f</lang>
close #f</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>use std::io::{self, Write};
<syntaxhighlight lang="rust">use std::io::{self, Write};
use std::fs::{DirBuilder, File};
use std::fs::{DirBuilder, File};
use std::path::Path;
use std::path::Path;
Line 2,237: Line 2,237:
let _ = writeln!(&mut io::stderr(), "Error: {}", error);
let _ = writeln!(&mut io::stderr(), "Error: {}", error);
process::exit(code)
process::exit(code)
}</lang>
}</syntaxhighlight>


=={{header|S-BASIC}}==
=={{header|S-BASIC}}==
Line 2,249: Line 2,249:


call upon the BDOS to switch to the desired directory.
call upon the BDOS to switch to the desired directory.
<syntaxhighlight lang="basic">
<lang BASIC>
rem -- Set the logged drive ('A' to 'P')
rem -- Set the logged drive ('A' to 'P')
procedure setdrive (drive = char)
procedure setdrive (drive = char)
Line 2,284: Line 2,284:


end
end
</syntaxhighlight>
</lang>




=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|Scala}}<lang scala>import java.io.File
{{libheader|Scala}}<syntaxhighlight lang="scala">import java.io.File


object CreateFile extends App {
object CreateFile extends App {
Line 2,299: Line 2,299:
try { new File(s"${File.separator}docs").mkdir() }
try { new File(s"${File.separator}docs").mkdir() }
catch { case e: Exception => println(s"Exception caught: $e with creating directory ${File.separator}docs") }
catch { case e: Exception => println(s"Exception caught: $e with creating directory ${File.separator}docs") }
}</lang>
}</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
<lang scheme>(open-output-file "output.txt")
<syntaxhighlight lang="scheme">(open-output-file "output.txt")
(open-output-file "/output.txt")</lang>
(open-output-file "/output.txt")</syntaxhighlight>
Results:
Results:
> file output.txt
> file output.txt
Line 2,318: Line 2,318:
when it is started by a normal user.
when it is started by a normal user.


<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "osfiles.s7i";
include "osfiles.s7i";


Line 2,331: Line 2,331:
close(aFile);
close(aFile);
mkdir("/docs");
mkdir("/docs");
end func;</lang>
end func;</syntaxhighlight>


Under Windows each filesystem has its own root.
Under Windows each filesystem has its own root.
Line 2,337: Line 2,337:


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<lang sensetalk>set the folder to "~/Desktop"
<syntaxhighlight lang="sensetalk">set the folder to "~/Desktop"
put "" into file "docs/output.txt"
put "" into file "docs/output.txt"
set the folder to "/"
set the folder to "/"
put empty into file "/docs/output.txt"</lang>
put empty into file "/docs/output.txt"</syntaxhighlight>
Or without defining a working directory:
Or without defining a working directory:
<lang sensetalk>put empty into file "~/Desktop/docs/output.txt"
<syntaxhighlight lang="sensetalk">put empty into file "~/Desktop/docs/output.txt"
put "" into file "/docs/output.txt"</lang>
put "" into file "/docs/output.txt"</syntaxhighlight>
Or using the Create command:
Or using the Create command:
<lang sensetalk>create file "output.txt"
<syntaxhighlight lang="sensetalk">create file "output.txt"
create folder "docs"</lang>
create folder "docs"</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby># Here
<syntaxhighlight lang="ruby"># Here
%f'output.txt' -> create;
%f'output.txt' -> create;
%d'docs' -> create;
%d'docs' -> create;
Line 2,355: Line 2,355:
# Root dir
# Root dir
Dir.root + %f'output.txt' -> create;
Dir.root + %f'output.txt' -> create;
Dir.root + %d'docs' -> create;</lang>
Dir.root + %d'docs' -> create;</syntaxhighlight>


=={{header|Slate}}==
=={{header|Slate}}==
File creation locally:
File creation locally:
<lang slate>(File newNamed: 'output.txt') touch.
<syntaxhighlight lang="slate">(File newNamed: 'output.txt') touch.
(Directory current / 'output.txt') touch.</lang>
(Directory current / 'output.txt') touch.</syntaxhighlight>


File creation at root:
File creation at root:
<lang slate>(File newNamed: '/output.txt') touch.
<syntaxhighlight lang="slate">(File newNamed: '/output.txt') touch.
(Directory root / 'output.txt') touch.</lang>
(Directory root / 'output.txt') touch.</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Line 2,370: Line 2,370:
[[Squeak]] has no notion of 'current directory' because it isn't tied to the shell that created it.
[[Squeak]] has no notion of 'current directory' because it isn't tied to the shell that created it.


<lang smalltalk>(FileDirectory on: 'c:\') newFileNamed: 'output.txt'; createDirectory: 'docs'.</lang>
<syntaxhighlight lang="smalltalk">(FileDirectory on: 'c:\') newFileNamed: 'output.txt'; createDirectory: 'docs'.</syntaxhighlight>


In [[GNU Smalltalk]] you can do instead:
In [[GNU Smalltalk]] you can do instead:


<lang smalltalk>ws := (File name: 'output.txt') writeStream.
<syntaxhighlight lang="smalltalk">ws := (File name: 'output.txt') writeStream.
ws close.
ws close.
Directory create: 'docs'.
Directory create: 'docs'.
Line 2,380: Line 2,380:
ws := (File name: '/output.txt') writeStream.
ws := (File name: '/output.txt') writeStream.
ws close.
ws close.
Directory create: '/docs'.</lang>
Directory create: '/docs'.</syntaxhighlight>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Line 2,387: Line 2,387:
{{works with|CSnobol}}
{{works with|CSnobol}}


<lang SNOBOL4> output(.file,1,'output.txt'); endfile(1) ;* Macro Spitbol
<syntaxhighlight lang="snobol4"> output(.file,1,'output.txt'); endfile(1) ;* Macro Spitbol
* output(.file,1,,'output.txt'); endfile(1) ;* CSnobol
* output(.file,1,,'output.txt'); endfile(1) ;* CSnobol
host(1,'mkdir docs')
host(1,'mkdir docs')
Line 2,394: Line 2,394:
* output(.file,1,,'/output.txt'); endfile(1) ;* CSnobol
* output(.file,1,,'/output.txt'); endfile(1) ;* CSnobol
host(1,'mkdir /docs')
host(1,'mkdir /docs')
end</lang>
end</syntaxhighlight>


=={{header|SQL PL}}==
=={{header|SQL PL}}==
{{works with|Db2 LUW}} version 9.7 or higher.
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
With SQL PL:
<lang sql pl>
<syntaxhighlight lang="sql pl">
BEGIN
BEGIN
DECLARE UTL_FILE_HANDLER UTL_FILE.FILE_TYPE;
DECLARE UTL_FILE_HANDLER UTL_FILE.FILE_TYPE;
Line 2,424: Line 2,424:
CALL UTL_FILE.FCLOSE(UTL_FILE_HANDLER);
CALL UTL_FILE.FCLOSE(UTL_FILE_HANDLER);
END @
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.
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.
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 2,442: Line 2,442:


=={{header|SQLite}}==
=={{header|SQLite}}==
<lang sqlite3>
<syntaxhighlight lang="sqlite3">
/*
/*
*Use '/' for *nix. Use whatever your root directory is on Windows.
*Use '/' for *nix. Use whatever your root directory is on Windows.
Line 2,451: Line 2,451:
.output output.txt
.output output.txt
.output /output.txt
.output /output.txt
</syntaxhighlight>
</lang>


=={{header|Standard ML}}==
=={{header|Standard ML}}==


<lang sml>let val out = TextIO.openOut "output.txt" in
<syntaxhighlight lang="sml">let val out = TextIO.openOut "output.txt" in
TextIO.closeOut out
TextIO.closeOut out
end;
end;


OS.FileSys.mkDir "docs";</lang>
OS.FileSys.mkDir "docs";</syntaxhighlight>


(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
(for creation in the filesystem root, replace the filenames by "/output.txt" and "/docs")
Line 2,467: Line 2,467:
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.
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.


<lang stata>file open f using output.txt, write replace
<syntaxhighlight lang="stata">file open f using output.txt, write replace
file close f
file close f
mkdir docs
mkdir docs
Line 2,473: Line 2,473:
file open f using \output.txt, write replace
file open f using \output.txt, write replace
file close f
file close f
mkdir \docs</lang>
mkdir \docs</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Line 2,479: Line 2,479:
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):
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):


<lang tcl>close [open output.txt w]
<syntaxhighlight lang="tcl">close [open output.txt w]
close [open [file nativename /output.txt] w]
close [open [file nativename /output.txt] w]


file mkdir docs
file mkdir docs
file mkdir [file nativename /docs]</lang>
file mkdir [file nativename /docs]</syntaxhighlight>


=={{header|Toka}}==
=={{header|Toka}}==


<lang toka>needs shell
<syntaxhighlight lang="toka">needs shell
" output.txt" "W" file.open file.close
" output.txt" "W" file.open file.close
" /output.txt" "W" file.open file.close
" /output.txt" "W" file.open file.close
Line 2,493: Line 2,493:
( Create the directories with permissions set to 777)
( Create the directories with permissions set to 777)
" docs" &777 mkdir
" docs" &777 mkdir
" /docs" &777 mkdir</lang>
" /docs" &777 mkdir</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
$$ MODE TUSCRIPT
- create file
- create file
Line 2,502: Line 2,502:
- create directory
- create directory
ERROR/STOP CREATE ("docs",project,-std-)
ERROR/STOP CREATE ("docs",project,-std-)
</syntaxhighlight>
</lang>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==


{{works with|Bourne Shell}}
{{works with|Bourne Shell}}
<lang bash>touch output.txt /output.txt # create both output.txt and /output.txt
<syntaxhighlight lang="bash">touch output.txt /output.txt # create both output.txt and /output.txt
mkdir /docs
mkdir /docs
mkdir docs # create both /docs and docs</lang>
mkdir docs # create both /docs and docs</syntaxhighlight>


{{works with|bash}}
{{works with|bash}}
<lang bash>touch {/,}output.txt # create both /output.txt and output.txt
<syntaxhighlight lang="bash">touch {/,}output.txt # create both /output.txt and output.txt
mkdir {/,}docs # create both /docs and docs</lang>
mkdir {/,}docs # create both /docs and docs</syntaxhighlight>


{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have a filesystem, just namespaced variables. -->
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have a filesystem, just namespaced variables. -->
Line 2,519: Line 2,519:


=={{header|Ursa}}==
=={{header|Ursa}}==
<lang ursa>decl file f
<syntaxhighlight lang="ursa">decl file f
f.create "output.txt"
f.create "output.txt"
f.createdir "docs"
f.createdir "docs"
Line 2,526: Line 2,526:
f.create "/output.txt"
f.create "/output.txt"
f.createdir "/docs"
f.createdir "/docs"
</syntaxhighlight>
</lang>


=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Public Sub create_file()
<syntaxhighlight lang="vb">Public Sub create_file()
Dim FileNumber As Integer
Dim FileNumber As Integer
FileNumber = FreeFile
FileNumber = FreeFile
Line 2,538: Line 2,538:
Open "C:\docs\output.txt" For Output As #FreeFile
Open "C:\docs\output.txt" For Output As #FreeFile
Close #FreeFile
Close #FreeFile
End Sub</lang>
End Sub</syntaxhighlight>


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")


Line 2,551: Line 2,551:
objFSO.CreateFolder("\docs")
objFSO.CreateFolder("\docs")
objFSO.CreateTextFile("\docs\output.txt")
objFSO.CreateTextFile("\docs\output.txt")
</syntaxhighlight>
</lang>


=={{header|Vedit macro language}}==
=={{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.
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.
<lang vedit>// In current directory
<syntaxhighlight lang="vedit">// In current directory
File_Open("input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close()
File_Open("input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close()
File_Mkdir("docs")
File_Mkdir("docs")
Line 2,561: Line 2,561:
// In the root directory
// In the root directory
File_Open("/input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close()
File_Open("/input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close()
File_Mkdir("/docs")</lang>
File_Mkdir("/docs")</syntaxhighlight>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
Line 2,568: Line 2,568:


{{works with|Visual Basic .NET|9.0+}}
{{works with|Visual Basic .NET|9.0+}}
<lang vbnet> 'Current Directory
<syntaxhighlight lang="vbnet"> 'Current Directory
IO.Directory.CreateDirectory("docs")
IO.Directory.CreateDirectory("docs")
IO.File.Create("output.txt").Close()
IO.File.Create("output.txt").Close()
Line 2,578: Line 2,578:
'Root, platform independent
'Root, platform independent
IO.Directory.CreateDirectory(IO.Path.DirectorySeparatorChar & "docs")
IO.Directory.CreateDirectory(IO.Path.DirectorySeparatorChar & "docs")
IO.File.Create(IO.Path.DirectorySeparatorChar & "output.txt").Close()</lang>
IO.File.Create(IO.Path.DirectorySeparatorChar & "output.txt").Close()</syntaxhighlight>


=={{header|Visual Objects}}==
=={{header|Visual Objects}}==
//Use Library System Library
//Use Library System Library
<lang visualfoxpro>
<syntaxhighlight lang="visualfoxpro">
DirMake(String2Psz("c:\docs"))
DirMake(String2Psz("c:\docs"))
FCreate("c:\docs\output.txt", FC_NORMAL)
FCreate("c:\docs\output.txt", FC_NORMAL)
</syntaxhighlight>
</lang>


{{omit from|SmileBASIC|Filesystem has no directories, only projects which cannot be manipulated by code.}}
{{omit from|SmileBASIC|Filesystem has no directories, only projects which cannot be manipulated by code.}}
Line 2,594: Line 2,594:


Wren does not currently support the creation of directories.
Wren does not currently support the creation of directories.
<lang ecmascript>import "io" for File
<syntaxhighlight lang="ecmascript">import "io" for File


// file is closed automatically after creation
// file is closed automatically after creation
Line 2,600: Line 2,600:


// check size
// check size
System.print("%(File.size("output.txt")) bytes")</lang>
System.print("%(File.size("output.txt")) bytes")</syntaxhighlight>


{{out}}
{{out}}
Line 2,609: Line 2,609:
=={{header|X86 Assembly}}==
=={{header|X86 Assembly}}==
{{works with|NASM|Linux}}
{{works with|NASM|Linux}}
<lang asm>
<syntaxhighlight lang="asm">
; syscall numbers for readability. :]
; syscall numbers for readability. :]


Line 2,664: Line 2,664:
int 0x80 ; Make kernel call
int 0x80 ; Make kernel call
ret
ret
</syntaxhighlight>
</lang>


=={{header|XPL0}}==
=={{header|XPL0}}==
Line 2,671: Line 2,671:
insert a slash at the beginning, like this: /output.txt
insert a slash at the beginning, like this: /output.txt


<syntaxhighlight lang="xpl0">
<lang XPL0>
int FD;
int FD;
FD:= FOpen("output.txt", 1);
FD:= FOpen("output.txt", 1);
</syntaxhighlight>
</lang>


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang yabasic>open "output.txt" for writing as #1
<syntaxhighlight lang="yabasic">open "output.txt" for writing as #1
close #1
close #1
Line 2,686: Line 2,686:
open "f:\docs\output.txt" for writing as #2
open "f:\docs\output.txt" for writing as #2
close #2
close #2
end if</lang>
end if</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
Works on Unix and Windows
Works on Unix and Windows
<lang zkl>$ ls -l docs
<syntaxhighlight lang="zkl">$ ls -l docs
ls: cannot access docs: No such file or directory
ls: cannot access docs: No such file or directory
$ zkl
$ zkl
Line 2,708: Line 2,708:
total 0
total 0
-rw-r--r-- 1 craigd craigd 0 Oct 27 22:08 output.txt
-rw-r--r-- 1 craigd craigd 0 Oct 27 22:08 output.txt
</syntaxhighlight>
</lang>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
Line 2,715: Line 2,715:
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:
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:


<lang zxbasic>SAVE "OUTPUT" CODE 16384,0</lang>
<syntaxhighlight lang="zxbasic">SAVE "OUTPUT" CODE 16384,0</syntaxhighlight>