Delete a file: Difference between revisions

no edit summary
(Ada solution added)
No edit summary
Line 4:
 
=={{header|Ada}}==
<lang ada>
with Ada.Directories; use Ada.Directories;
</adalang>
and then
<lang ada>
Delete_File ("input.txt");
Delete_File ("/input.txt");
Delete_Tree ("docs");
Delete_Tree ("/docs");
</adalang>
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}}==
Note: <codett>scratch</codett> does not appear to do anything on [[ALGOL 68G]]. Also note that file names are Operating System dependent.
<pre>
main:(
Line 39:
=={{header|C}}==
ISO C:
<lang c>#include <stdio.h>
 
int main() {
Line 47:
remove("/docs");
return 0;
}</clang>
 
POSIX:
<lang c>#include <unistd.h>
 
int main() {
Line 58:
rmdir("/docs");
return 0;
}</clang>
 
=={{header|D}}==
{{libheader|Tango}}
<lang d>import tango.io.Path;
 
void main() {
Line 69:
remove("docs");
remove("/docs");
}</dlang>
 
{{libheader|Tango}}
POSIX:
<lang d>import tango.stdc.posix.unistd;
 
void main() {
Line 80:
rmdir("docs");
rmdir("/docs");
}</dlang>
 
=={{header|Forth}}==
Line 115:
=={{header|Java}}==
 
<lang java>import java.util.File;
public class FileDeleteTest {
public static boolean deleteFile(String filename) {
Line 132:
test("directory", File.seperator + "docs" + File.seperator);
}
}</javalang>
 
=={{header|MAXScript}}==
Line 143:
=={{header|OCaml}}==
 
<lang ocaml>Sys.remove "input.txt";;
Sys.remove "/input.txt";;</ocamllang>
 
with the Unix library:
<lang ocaml>#load "unix.cma";;
Unix.unlink "input.txt";;
Unix.unlink "/input.txt";;
Unix.rmdir "docs";;
Unix.rmdir "/docs";;</ocamllang>
 
=={{header|Perl}}==
 
<lang perl>use File::Spec::Functions qw(catfile rootdir);
# here
unlink 'input.txt';
Line 161:
# root dir
unlink catfile rootdir, 'input.txt';
rmdir catfile rootdir, 'docs';</perllang>
 
'''Without Perl Modules'''
Line 183:
=={{header|Python}}==
 
<lang python>import os
# current directory
os.remove("output.txt")
Line 189:
# root directory
os.remove("/output.txt")
os.rmdir("/docs")</pythonlang>
 
=={{header|Raven}}==