Create a file: Difference between revisions

From Rosetta Code
Content added Content deleted
m (whitespace and lang tags)
Line 8: Line 8:
* 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;
<lang ada>
with Ada.Streams.Stream_IO, Ada.Directories;
use Ada.Streams.Stream_IO, Ada.Directories;
use Ada.Streams.Stream_IO, Ada.Directories;


Line 25: Line 24:
Create_Directory("/docs");
Create_Directory("/docs");
end File_Creation;
end File_Creation;</lang>
</lang>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Line 35: Line 33:
{{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.
<pre>
<pre>main:(
main:(


INT errno;
INT errno;
Line 73: Line 70:


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

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


=={{header|AWK}}==
=={{header|AWK}}==
Line 93: Line 88:
=={{header|C}}==
=={{header|C}}==


<lang c>
<lang c>#include <stdio.h>
#include <stdio.h>


int main() {
int main() {
Line 101: Line 95:


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


{{works with|POSIX}}
{{works with|POSIX}}
<lang c>
<lang c>#include <sys/stat.h>
#include <sys/stat.h>


int main() {
int main() {
Line 112: Line 104:


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


(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 171: Line 162:
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>
<lang d>module fileio ;
module fileio ;
import std.stdio ;
import std.stdio ;
import std.path ;
import std.path ;
Line 217: Line 207:
writefln("== test: File & Dir Creation ==") ;
writefln("== test: File & Dir Creation ==") ;
testCreate("output.txt", "docs") ;
testCreate("output.txt", "docs") ;
}</lang>
}
</lang>


=={{header|DOS Batch File}}==
=={{header|DOS Batch File}}==
Line 230: Line 219:
<file:///output.txt>.setBytes([])
<file:///output.txt>.setBytes([])
<file:///docs>.mkdir(null)</lang>
<file:///docs>.mkdir(null)</lang>



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


=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
{{works with|Fortran|90 and later}}
Don't know a way of creating directories in Fortran
Don't know a way of creating directories in Fortran
<lang fortran>OPEN (UNIT=5, FILE="output.txt", STATUS="NEW") ! Current directory
<lang fortran>
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW") ! Current directory
CLOSE (UNIT=5)
CLOSE (UNIT=5)
OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW") ! Root directory
OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW") ! Root directory
CLOSE (UNIT=5)
CLOSE (UNIT=5)</lang>
</lang>


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


<lang haskell>
<lang haskell>import System.Directory
import System.Directory


createFile name = writeFile name ""
createFile name = writeFile name ""
Line 258: Line 243:
createDirectory "docs"
createDirectory "docs"
createFile "/output.txt"
createFile "/output.txt"
createDirectory "/docs"
createDirectory "/docs"</lang>
</lang>


=={{header|Java}}==
=={{header|Java}}==


<lang java5>
<lang java5>import java.util.File;
import java.util.File;
public class CreateFileTest {
public class CreateFileTest {
public static String createNewFile(String filename) {
public static String createNewFile(String filename) {
Line 290: Line 273:
test("directory", File.seperator + "docs" + File.seperator);
test("directory", File.seperator + "docs" + File.seperator);
}
}
}</lang>
}
</lang>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
Line 312: Line 294:
=={{header|OCaml}}==
=={{header|OCaml}}==


<lang ocaml>
<lang ocaml># let oc = open_out "output.txt" in
# 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 = ()
- : unit = ()</lang>
</lang>


(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|Perl}}==
=={{header|Perl}}==
<lang perl>use File::Spec::Functions qw(catfile rootdir);
<lang perl>
use File::Spec::Functions qw(catfile rootdir);
{ # here
{ # here
open my $fh, '>', 'output.txt';
open my $fh, '>', 'output.txt';
Line 333: Line 312:
open my $fh, '>', catfile rootdir, 'output.txt';
open my $fh, '>', catfile rootdir, 'output.txt';
mkdir catfile rootdir, 'docs';
mkdir catfile rootdir, 'docs';
};
};</lang>
</lang>


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


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


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


=={{header|Python}}==
=={{header|Python}}==
Line 354: Line 328:
Current directory
Current directory


<lang python>
<lang python> import os
import os
f = open("output.txt", "w")
f = open("output.txt", "w")
f.close()
f.close()
os.mkdir("docs")
os.mkdir("docs")</lang>
</lang>


Root directory
Root directory


<lang python>
<lang python> f = open("/output.txt", "w")
f = open("/output.txt", "w")
f.close()
f.close()
os.mkdir("/docs")
os.mkdir("/docs")</lang>
</lang>


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


<lang python>
<lang python> from __future__ import with_statement
from __future__ import with_statement
import os
import os
def create(dir):
def create(dir):
Line 381: Line 350:
create(".") # current directory
create(".") # current directory
create("/") # root directory
create("/") # root directory</lang>
</lang>


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


Line 407: Line 374:
=={{header|Ruby}}==
=={{header|Ruby}}==


<lang ruby>
<lang ruby># Current directory
#Current directory
open("output.txt", "w") { }
open("output.txt", "w") { }
Dir.mkdir("docs")
Dir.mkdir("docs")


#Root directory
# Root directory
open("/output.txt", "w") { }
open("/output.txt", "w") { }
Dir.mkdir("/docs")
Dir.mkdir("/docs")</lang>
</lang>


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


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


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==


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>
<lang smalltalk>
(FileDirectory on: 'c:\') newFileNamed: 'output.txt'; createDirectory: 'docs'.
</lang>


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


<lang smalltalk>
<lang smalltalk>ws := (File name: 'output.txt') writeStream.
ws := (File name: 'output.txt') writeStream.
ws close.
ws close.
Directory create: 'docs'.
Directory create: 'docs'.
Line 447: Line 405:
ws := (File name: '/output.txt') writeStream.
ws := (File name: '/output.txt') writeStream.
ws close.
ws close.
Directory create: '/docs'.
Directory create: '/docs'.</lang>
</lang>


=={{header|Standard ML}}==
=={{header|Standard ML}}==
Line 464: Line 421:
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>
<lang tcl>close [open output.txt w]
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]
file mkdir [file nativename /docs]</lang>
</lang>


=={{header|Toka}}==
=={{header|Toka}}==
Line 484: Line 439:
=={{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>
<lang vedit>// In current directory
// 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 491: Line 445:
// 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")
File_Mkdir("/docs")</lang>
</lang>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
Line 499: Line 452:


{{works with|Visual Basic .NET|9.0+}}
{{works with|Visual Basic .NET|9.0+}}
<lang vb>
<lang vb> 'Current Directory
'Current Directory
IO.Directory.CreateDirectory("docs")
IO.Directory.CreateDirectory("docs")
IO.File.Create("output.txt").Close()
IO.File.Create("output.txt").Close()
Line 510: Line 462:
'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()
IO.File.Create(IO.Path.DirectorySeparatorChar & "output.txt").Close()</lang>
</lang>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works with|bash}}

<lang bash>
<lang bash>touch output.txt
touch output.txt
touch /output.txt
touch /output.txt
mkdir docs
mkdir docs
mkdir /docs
mkdir /docs</lang>
</lang>

Revision as of 19:32, 28 July 2009

Task
Create a file
You are encouraged to solve this task according to the task description, using any language you may know.

In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.

Ada

Notes:

  • Use Streams_IO to write 0 bytes. File creation with Ada.Text_IO does not create 0 byte files (it inserts EOL/EOF).
  • The forward slash (/) notation works in Windows XP as well as Unix/Linux.

<lang ada>with Ada.Streams.Stream_IO, Ada.Directories; use Ada.Streams.Stream_IO, Ada.Directories;

procedure File_Creation is

  File_Handle : File_Type;
  

begin

  Create (File_Handle, Out_File, "output.txt");
  Close (File_Handle);
  Create_Directory("docs");
  Create (File_Handle, Out_File, "/output.txt");
  Close (File_Handle);
  Create_Directory("/docs");
  

end File_Creation;</lang>

ALGOL 68

Note: file names are Operating System dependent.

  • ALGOL 68G does not support pages, and "set" procedure only has 2 arguments.
  • ELLA ALGOL 68 also encounters problems with "set" page on linux.
Works with: ALGOL 68 version Standard - no extensions to language used

It may be best to to use an operating system provided library.

main:(

  INT errno;

  PROC touch = (STRING file name)INT:
  BEGIN
    FILE actual file;
    INT errno := open(actual file, file name, stand out channel);
    IF errno NE 0 THEN GO TO stop touch FI;
    close(actual file); # detach the book and keep it #
    errno
  EXIT
  stop touch:
      errno
  END;

  errno := touch("input.txt");
  errno := touch("/input.txt");

  # ALGOL 68 has no concept of directories,
    however a file can have multiple pages,
    the pages are identified by page number only #

  PROC mkpage = (STRING file name, INT page x)INT:
  BEGIN
    FILE actual file;
    INT errno := open(actual file, file name, stand out channel);
    IF errno NE 0 THEN GO TO stop mkpage FI;
    set(actual file,page x,1,1); # skip to page x, line 1, character 1 #
    close(actual file); # detach the new page and keep it #
    errno
  EXIT
  stop mkpage:
      errno
  END;

  errno := mkpage("input.txt",2);
)

AutoHotkey

<lang AutoHotkey>FileAppend,,output.txt FileCreateDir, docs FileAppend,,c:\output.txt FileCreateDir, c:\docs</lang>

AWK

There's no way to create a directory, except by calling an extern program (like mkdir) to do so. <lang awk>BEGIN {

 printf "" > "output.txt"
 # try to create the file in the root (for *nix-like systems)
 printf "" > "/output.txt"

}</lang>

C

<lang c>#include <stdio.h>

int main() {

 FILE *fh = fopen("output.txt", "w");
 fclose(fh);
 return 0;

}</lang>

Works with: POSIX

<lang c>#include <sys/stat.h>

int main() {

 mkdir("docs", 0750); /* rights 0750 for rwxr-x--- */
 return 0;

}</lang>

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

C++

<lang cpp>#include <fstream>

  1. include <direct.h>

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; }</lang>

C#

<lang csharp>using System; using System.IO;

class Program {

   static void Main(string[] args) {
       File.Create("output.txt");
       File.Create(@"\output.txt");
       Directory.CreateDirectory("docs");
       Directory.CreateDirectory(@"\docs");
   }

}</lang>

Common Lisp

Lisp provides open and close commands for I/O with files<lang lisp>(let ((stream (open "output.txt" :direction :output)))

 (close stream))</lang>

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)

   ;; use the stream here
)</lang>

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"))

                    (make-pathname :directory '(:absolute "docs")))))
 (mapcar #'ensure-directories-exist paths))</lang>

So creating a file called output.txt with an absolute path in the root directory becomes: <lang lisp>(with-open-file

   (stream 
       (make-pathname :directory '(:absolute "") :name "output.txt")
       :direction :output))</lang>

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>

D

For file creation, std.file.write function & std.stream.file class are used.
For dir creation, std.file.mkdir is used. <lang d>module fileio ; import std.stdio ; import std.path ; import std.file ; import std.stream ;

string[] genName(string name){

 string cwd  = curdir ~ sep ; // on current directory
 string root = sep ;          // on root 
 name = std.path.getBaseName(name) ;  
 return [cwd ~ name, root ~ name] ;

} void Remove(string target){

 if(exists(target)){
   if (isfile(target)) 
     std.file.remove(target);
   else
     std.file.rmdir(target) ;
 }

} void testCreate(string filename, string dirname){

 // files:
 foreach(fn ; genName(filename))
   try{
     writefln("file to be created : %s", fn) ;
     std.file.write(fn, cast(void[])null) ; 
     writefln("\tsuccess by std.file.write") ; Remove(fn) ;
     (new std.stream.File(fn, FileMode.OutNew)).close() ; 
     writefln("\tsuccess by std.stream") ; Remove(fn) ;
   } catch(Exception e) {
     writefln(e.msg) ;
   }
 // dirs:
 foreach(dn ; genName(dirname))
   try{
     writefln("dir to be created : %s", dn) ;
     std.file.mkdir(dn) ; 
     writefln("\tsuccess by std.file.mkdir") ; Remove(dn) ;
   } catch(Exception e) {
     writefln(e.msg) ;
   }

} void main(){

 writefln("== test: File & Dir Creation ==") ;
 testCreate("output.txt", "docs") ;

}</lang>

DOS Batch File

 md docs
 md \docs

E

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

Forth

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

s" /output.txt" w/o create-file throw ( fileid) drop</lang>

Fortran

Works with: Fortran version 90 and later

Don't know a way of creating directories in Fortran <lang fortran>OPEN (UNIT=5, FILE="output.txt", STATUS="NEW")  ! Current directory CLOSE (UNIT=5) OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW")  ! Root directory CLOSE (UNIT=5)</lang>

Haskell

<lang haskell>import System.Directory

createFile name = writeFile name ""

main = do

 createFile "output.txt"
 createDirectory "docs"
 createFile "/output.txt"
 createDirectory "/docs"</lang>

Java

<lang java5>import java.util.File; public class CreateFileTest {

  public static String createNewFile(String filename) {
      try {
          // Create file if it does not exist
          boolean success = new File(filename).createNewFile();
          if (success) {
              return " did not exist and was created successfully.";
          } else {
              return " already exists.";
          }
      } catch (IOException e) {
              return " could not be created.";
      }
  }
  public static void test(String type, String filename) {
      System.out.println("The following " + type + " called " + filename + 
          createNewFile(filename)
      );
  }
  public static void main(String args[]) {
       test("file", "output.txt");
       test("file", File.seperator + "output.txt");
       test("directory", "docs");
       test("directory", File.seperator + "docs" + File.seperator);
  }

}</lang>

MAXScript

-- Here
f = createFile "output.txt"
close f
makeDir (sysInfo.currentDir + "\docs")
-- System root
f = createFile "\output.txt"
close f
makeDir ("c:\docs")

Objective-C

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

[fm createFileAtPath:@"output.txt" contents:[NSData data] attributes:nil]; [fm createDirectoryAtPath:@"docs" attributes:nil];</lang>

OCaml

<lang ocaml># let oc = open_out "output.txt" in

 close_out oc;;

- : unit = ()

  1. Unix.mkdir "docs" 0o750 ;; (* rights 0o750 for rwxr-x--- *)

- : unit = ()</lang>

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

Perl

<lang perl>use File::Spec::Functions qw(catfile rootdir); { # here

   open my $fh, '>', 'output.txt';
   mkdir 'docs';

}; { # root dir

   open my $fh, '>', catfile rootdir, 'output.txt';
   mkdir catfile rootdir, 'docs';

};</lang>

Without Perl Modules

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

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

Python

Current directory

<lang python> import os

f = open("output.txt", "w")
f.close()
os.mkdir("docs")</lang>

Root directory

<lang python> f = open("/output.txt", "w")

f.close()
os.mkdir("/docs")</lang>
Works with: Python version 2.5

Exception-safe way to create file:

<lang python> from __future__ import with_statement

import os
def create(dir):
    with open(os.path.join(dir, "output.txt"), "w"):
        pass
    os.mkdir(os.path.join(dir, "docs"))
   
create(".") # current directory
create("/") # root directory</lang>

R

<lang R>f <- file("output.txt", "w") close(f)

  1. it may fails and the exact syntax to achieve the root
  2. changes according to the operating system

f <- file("/output.txt", "w") close(f)

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

Raven

"" as str
str 'output.txt'  write
str '/output.txt' write
'docs'  mkdir
'/docs' mkdir

Ruby

<lang ruby># Current directory open("output.txt", "w") { } Dir.mkdir("docs")

  1. Root directory

open("/output.txt", "w") { } Dir.mkdir("/docs")</lang>

Slate

File creation locally: <lang slate>(File newNamed: 'output.txt') touch. (Directory current / 'output.txt') touch.</lang>

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

Smalltalk

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>

In GNU Smalltalk you can do instead:

<lang smalltalk>ws := (File name: 'output.txt') writeStream. ws close. Directory create: 'docs'.

ws := (File name: '/output.txt') writeStream. ws close. Directory create: '/docs'.</lang>

Standard ML

<lang sml>let val out = TextIO.openOut "output.txt" in

 TextIO.closeOut out

end;

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

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

Tcl

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] close [open [file nativename /output.txt] w]

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

Toka

 needs shell
 " output.txt" "W" file.open file.close
 " /output.txt" "W" file.open file.close

 ( Create the directories with permissions set to 777)
 " docs" &777 mkdir
 " /docs" &777 mkdir

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. <lang vedit>// In current directory File_Open("input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close() File_Mkdir("docs")

// In the root directory File_Open("/input.txt") Ins_Char(' ') Del_Char(-1) Buf_Close() File_Mkdir("/docs")</lang>

Visual Basic .NET

Platform: .NET

Works with: Visual Basic .NET version 9.0+

<lang vb> 'Current Directory IO.Directory.CreateDirectory("docs") IO.File.Create("output.txt").Close()

'Root

IO.Directory.CreateDirectory("\docs") IO.File.Create("\output.txt").Close()

'Root, platform independent

IO.Directory.CreateDirectory(IO.Path.DirectorySeparatorChar & "docs") IO.File.Create(IO.Path.DirectorySeparatorChar & "output.txt").Close()</lang>

UNIX Shell

Works with: bash

<lang bash>touch output.txt touch /output.txt mkdir docs mkdir /docs</lang>