Delete a file: Difference between revisions

Content added Content deleted
m (whitespace and lang tags)
Line 4: Line 4:


=={{header|Ada}}==
=={{header|Ada}}==
<lang ada>with Ada.Directories; use Ada.Directories;</lang>
<lang ada>
with Ada.Directories; use Ada.Directories;
</lang>
and then
and then
<lang ada>
<lang ada>Delete_File ("input.txt");
Delete_File ("input.txt");
Delete_File ("/input.txt");
Delete_File ("/input.txt");
Delete_Tree ("docs");
Delete_Tree ("docs");
Delete_Tree ("/docs");
Delete_Tree ("/docs");</lang>
</lang>
Naming conventions for the file path are [[OS]]-specific. The language does not specify the encoding of the file paths, the directory separators or brackets, the file extension delimiter, the file version delimiter and syntax. The example provided works under [[Linux]] and [[Windows]].
Naming conventions for the file path are [[OS]]-specific. The language does not specify the encoding of the file paths, the directory separators or brackets, the file extension delimiter, the file version delimiter and syntax. The example provided works under [[Linux]] and [[Windows]].

=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Note: <tt>scratch</tt> does not appear to do anything on [[ALGOL 68G]]. Also note that file names are Operating System dependent.
Note: <tt>scratch</tt> does not appear to do anything on [[ALGOL 68G]]. Also note that file names are Operating System dependent.
<pre>
<pre>main:(
main:(
PROC remove = (STRING file name)INT:
PROC remove = (STRING file name)INT:
BEGIN
BEGIN
Line 34: Line 30:
remove("docs");
remove("docs");
remove("/docs")
remove("/docs")
)</pre>
)
</pre>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>
<lang AutoHotkey>FileDelete, input.txt
FileDelete, input.txt
FileDelete, \input.txt
FileDelete, \input.txt
FileRemoveDir, docs, 1
FileRemoveDir, docs, 1
FileRemoveDir, \docs, 1
FileRemoveDir, \docs, 1</lang>
</lang>


=={{header|AWK}}==
=={{header|AWK}}==
Assuming we are ona Unix/Linux or at least Cygwin system:
Assuming we are ona Unix/Linux or at least Cygwin system:
system("rm input.txt");
<lang awk> system("rm input.txt");
system("rm /input.txt");
system("rm /input.txt");
system("rm -rf docs");
system("rm -rf docs");
system("rm -rf /docs");
system("rm -rf /docs");</lang>



=={{header|C}}==
=={{header|C}}==
Line 161: Line 153:
{{works with|Fortran|90 and later}}
{{works with|Fortran|90 and later}}
I don't know a way of deleting directories in Fortran
I don't know a way of deleting directories in Fortran
OPEN (UNIT=5, FILE="input.txt", STATUS="OLD") ! Current directory
<lang fortran> OPEN (UNIT=5, FILE="input.txt", STATUS="OLD") ! Current directory
CLOSE (UNIT=5, STATUS="DELETE")
CLOSE (UNIT=5, STATUS="DELETE")
OPEN (UNIT=5, FILE="/input.txt", STATUS="OLD") ! Root directory
OPEN (UNIT=5, FILE="/input.txt", STATUS="OLD") ! Root directory
CLOSE (UNIT=5, STATUS="DELETE")
CLOSE (UNIT=5, STATUS="DELETE")</lang>
=={{header|Haskell}}==
=={{header|Haskell}}==


import System.IO
<lang haskell> import System.IO
import System.Directory
import System.Directory
Line 175: Line 167:
removeDirectory "docs"
removeDirectory "docs"
removeFile "/output.txt"
removeFile "/output.txt"
removeDirectory "/docs"
removeDirectory "/docs"</lang>


=={{header|Io}}==
=={{header|Io}}==
Directory fileNamed("input.txt") remove
<lang io> Directory fileNamed("input.txt") remove
Directory directoryNamed("docs") remove
Directory directoryNamed("docs") remove
RootDir := Directory clone setPath("/")
RootDir := Directory clone setPath("/")
RootDir fileNamed("input.txt") remove
RootDir fileNamed("input.txt") remove
RootDir directoryNamed("docs") remove
RootDir directoryNamed("docs") remove</lang>


=={{header|Java}}==
=={{header|Java}}==
Line 208: Line 200:
{{works with|UCB Logo}}
{{works with|UCB Logo}}
UCB Logo has no means to delete directories.
UCB Logo has no means to delete directories.
<lang logo>
<lang logo>erasefile "input.txt
erasefile "input.txt
erasefile "/input.txt</logo>
erasefile "/input.txt
</logo>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
Line 301: Line 291:
=={{header|Ruby}}==
=={{header|Ruby}}==


<lang ruby> File.delete("output.txt", "/output.txt")
#!/usr/bin/env ruby
File.delete("output.txt", "/output.txt")
Dir.delete("docs")
Dir.delete("docs")
Dir.delete("/docs")
Dir.delete("/docs")</lang>


=={{header|Slate}}==
=={{header|Slate}}==
Line 310: Line 299:
(It will succeed deleting the directory if it is empty)
(It will succeed deleting the directory if it is empty)


<lang slate>
<lang slate>(File newNamed: 'input.txt') delete.
(File newNamed: 'input.txt') delete.
(File newNamed: '/input.txt') delete.
(File newNamed: '/input.txt') delete.
(Directory newNamed: 'docs') delete.
(Directory newNamed: 'docs') delete.
(Directory newNamed: '/docs') delete.
(Directory newNamed: '/docs') delete.</lang>
</lang>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Line 350: Line 337:


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
rm -rf docs
<lang bash> rm -rf docs
rm input.txt
rm input.txt
rm -rf /docs
rm -rf /docs
rm /input.txt
rm /input.txt</lang>


=={{header|Vedit macro language}}==
=={{header|Vedit macro language}}==
Vedit allows using either '\' or '/' as directory separator character, it is automatically converted to the one used by the operating system.
Vedit allows using either '\' or '/' as directory separator character, it is automatically converted to the one used by the operating system.
<lang vedit>
<lang vedit>// In current directory
// In current directory
File_Delete("input.txt", OK)
File_Delete("input.txt", OK)
File_Rmdir("docs")
File_Rmdir("docs")
Line 364: Line 350:
// In the root directory
// In the root directory
File_Delete("/input.txt", OK)
File_Delete("/input.txt", OK)
File_Rmdir("/docs")
File_Rmdir("/docs")</lang>
</lang>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==