Delete a file: Difference between revisions
Content added Content deleted
(add BQN) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8: | Line 8: | ||
=={{header|11l}}== |
=={{header|11l}}== |
||
< |
<syntaxhighlight lang="11l">fs:remove_file(‘output.txt’) |
||
fs:remove_dir(‘docs’) |
fs:remove_dir(‘docs’) |
||
fs:remove_file(‘/output.txt’) |
fs:remove_file(‘/output.txt’) |
||
fs:remove_dir(‘/docs’)</ |
fs:remove_dir(‘/docs’)</syntaxhighlight> |
||
=={{header|8th}}== |
=={{header|8th}}== |
||
<syntaxhighlight lang="forth"> |
|||
<lang Forth> |
|||
"input.txt" f:rm drop |
"input.txt" f:rm drop |
||
"/input.txt" f:rm drop |
"/input.txt" f:rm drop |
||
"docs" f:rmdir drop |
"docs" f:rmdir drop |
||
"/docs" f:rmdir drop |
"/docs" f:rmdir drop |
||
</syntaxhighlight> |
|||
</lang> |
|||
The 'drop' removes the result (true or false, indicating success or failure). It is not strictly necessary to do so, but it keeps the stack clean. |
The 'drop' removes the result (true or false, indicating success or failure). It is not strictly necessary to do so, but it keeps the stack clean. |
||
=={{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 deleteFic64.s */ |
/* program deleteFic64.s */ |
||
Line 104: | Line 104: | ||
/* for this file see task include a file in language AArch64 assembly */ |
/* for this file see task include a file in language AArch64 assembly */ |
||
.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. |
||
< |
<syntaxhighlight lang="action!">PROC Dir(CHAR ARRAY filter) |
||
CHAR ARRAY line(255) |
CHAR ARRAY line(255) |
||
BYTE dev=[1] |
BYTE dev=[1] |
||
Line 141: | Line 141: | ||
PrintF("Dir ""%S""%E",filter) |
PrintF("Dir ""%S""%E",filter) |
||
Dir(filter) |
Dir(filter) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Delete_a_file.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Delete_a_file.png Screenshot from Atari 8-bit computer] |
||
Line 160: | Line 160: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Directories; use Ada.Directories;</syntaxhighlight> |
||
and then |
and then |
||
< |
<syntaxhighlight lang="ada">Delete_File ("input.txt"); |
||
Delete_File ("/input.txt"); |
Delete_File ("/input.txt"); |
||
Delete_Tree ("docs"); |
Delete_Tree ("docs"); |
||
Delete_Tree ("/docs");</ |
Delete_Tree ("/docs");</syntaxhighlight> |
||
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|Aikido}}== |
=={{header|Aikido}}== |
||
The <code>remove</code> function removes either a file or a directory (the directory must be empty for this to work). Exception is thrown if this fails. |
The <code>remove</code> function removes either a file or a directory (the directory must be empty for this to work). Exception is thrown if this fails. |
||
< |
<syntaxhighlight lang="aikido"> |
||
remove ("input.txt") |
remove ("input.txt") |
||
remove ("/input.txt") |
remove ("/input.txt") |
||
remove ("docs") |
remove ("docs") |
||
remove ("/docs") |
remove ("/docs") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Aime}}== |
=={{header|Aime}}== |
||
< |
<syntaxhighlight lang="aime">remove("input.txt"); |
||
remove("/input.txt"); |
remove("/input.txt"); |
||
remove("docs"); |
remove("docs"); |
||
remove("/docs");</ |
remove("/docs");</syntaxhighlight> |
||
=={{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. |
||
< |
<syntaxhighlight lang="algol68">main:( |
||
PROC remove = (STRING file name)INT: |
PROC remove = (STRING file name)INT: |
||
BEGIN |
BEGIN |
||
Line 201: | Line 201: | ||
remove("docs"); |
remove("docs"); |
||
remove("/docs") |
remove("/docs") |
||
)</ |
)</syntaxhighlight> |
||
=={{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 */ |
||
/* program deleteFic.s */ |
/* program deleteFic.s */ |
||
Line 283: | Line 283: | ||
/***************************************************/ |
/***************************************************/ |
||
.include "../affichage.inc" |
.include "../affichage.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">file: "input.txt" |
||
docs: "docs" |
docs: "docs" |
||
Line 293: | Line 293: | ||
delete join.path ["/" file] |
delete join.path ["/" file] |
||
delete.directory join.path ["/" docs]</ |
delete.directory join.path ["/" docs]</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">FileDelete, input.txt |
||
FileDelete, \input.txt |
FileDelete, \input.txt |
||
FileRemoveDir, docs, 1 |
FileRemoveDir, docs, 1 |
||
FileRemoveDir, \docs, 1</ |
FileRemoveDir, \docs, 1</syntaxhighlight> |
||
===with DllCall=== |
===with DllCall=== |
||
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ DeleteFile @github] by jNizM |
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ DeleteFile @github] by jNizM |
||
< |
<syntaxhighlight lang="autohotkey">DeleteFile(lpFileName) |
||
{ |
{ |
||
DllCall("Kernel32.dll\DeleteFile", "Str", lpFileName) |
DllCall("Kernel32.dll\DeleteFile", "Str", lpFileName) |
||
} |
} |
||
DeleteFile("C:\Temp\TestFile.txt")</ |
DeleteFile("C:\Temp\TestFile.txt")</syntaxhighlight> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
Assuming we are on a Unix/Linux or at least Cygwin system: |
Assuming we are on a Unix/Linux or at least Cygwin system: |
||
< |
<syntaxhighlight 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")</syntaxhighlight> |
||
=={{header|Axe}}== |
=={{header|Axe}}== |
||
< |
<syntaxhighlight lang="axe">DelVar "appvINPUT"</syntaxhighlight> |
||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
Line 326: | Line 326: | ||
Some versions of Qbasic may have had a builtin RMDIR command. However this is not documented in the manual, so we use the external MSDOS command in this example. |
Some versions of Qbasic may have had a builtin RMDIR command. However this is not documented in the manual, so we use the external MSDOS command in this example. |
||
< |
<syntaxhighlight lang="qbasic"> |
||
KILL "INPUT.TXT" |
KILL "INPUT.TXT" |
||
KILL "C:\INPUT.TXT" |
KILL "C:\INPUT.TXT" |
||
SHELL "RMDIR /S /Q DIR" |
SHELL "RMDIR /S /Q DIR" |
||
SHELL "RMDIR /S /Q C:\DIR" |
SHELL "RMDIR /S /Q C:\DIR" |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{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. |
||
< |
<syntaxhighlight lang="gwbasic"> 0 PRINT CHR$ (4)"DELETE INPUT.TXT"</syntaxhighlight> |
||
==={{header|BaCon}}=== |
==={{header|BaCon}}=== |
||
BaCon has a <tt>DELETE</tt> instruction, that accepts <tt>FILE|DIRECTORY|RECURSIVE</tt> options. |
BaCon has a <tt>DELETE</tt> instruction, that accepts <tt>FILE|DIRECTORY|RECURSIVE</tt> options. |
||
< |
<syntaxhighlight lang="freebasic">DELETE FILE "input.txt" |
||
DELETE FILE "/input.txt"</ |
DELETE FILE "/input.txt"</syntaxhighlight> |
||
Errors can be caught with the <tt>CATCH GOTO label</tt> instruction (which allows <tt>RESUME</tt> from the labelled code section). |
Errors can be caught with the <tt>CATCH GOTO label</tt> instruction (which allows <tt>RESUME</tt> from the labelled code section). |
||
Line 349: | Line 349: | ||
file extensions. Here we delete the file named INPUTTXT from the first microdrive: |
file extensions. Here we delete the file named INPUTTXT from the first microdrive: |
||
< |
<syntaxhighlight lang="zxbasic"> |
||
ERASE "m"; 1; "INPUTTXT" |
ERASE "m"; 1; "INPUTTXT" |
||
</syntaxhighlight> |
|||
</lang> |
|||
And for disc drive of ZX Spectrum +3: |
And for disc drive of ZX Spectrum +3: |
||
< |
<syntaxhighlight lang="zxbasic"> |
||
ERASE "a:INPUTTXT" |
ERASE "a:INPUTTXT" |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|BBC BASIC}}=== |
==={{header|BBC BASIC}}=== |
||
If the names are known as constants at compile time: |
If the names are known as constants at compile time: |
||
< |
<syntaxhighlight lang="bbcbasic"> |
||
*DELETE input.txt |
*DELETE input.txt |
||
*DELETE \input.txt |
*DELETE \input.txt |
||
*RMDIR docs |
*RMDIR docs |
||
*RMDIR \docs |
*RMDIR \docs |
||
</syntaxhighlight> |
|||
</lang> |
|||
If the names are known only at run time: |
If the names are known only at run time: |
||
< |
<syntaxhighlight lang="bbc basic"> OSCLI "DELETE " + file$ |
||
OSCLI "RMDIR " + dir$</ |
OSCLI "RMDIR " + dir$</syntaxhighlight> |
||
==={{header|IS-BASIC}}=== |
==={{header|IS-BASIC}}=== |
||
< |
<syntaxhighlight lang="is-basic">100 WHEN EXCEPTION USE IOERROR |
||
110 EXT "del input.txt" |
110 EXT "del input.txt" |
||
120 EXT "del \input.txt" |
120 EXT "del \input.txt" |
||
Line 382: | Line 382: | ||
180 PRINT "*** ";EXSTRING$(EXTYPE) |
180 PRINT "*** ";EXSTRING$(EXTYPE) |
||
190 CONTINUE |
190 CONTINUE |
||
200 END HANDLER</ |
200 END HANDLER</syntaxhighlight> |
||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
< |
<syntaxhighlight lang="dos">del input.txt |
||
rd /s /q docs |
rd /s /q docs |
||
del \input.txt |
del \input.txt |
||
rd /s /q \docs</ |
rd /s /q \docs</syntaxhighlight> |
||
=={{header|BQN}}== |
=={{header|BQN}}== |
||
File operations are under the system value <code>•file</code> in BQN. |
File operations are under the system value <code>•file</code> in BQN. |
||
< |
<syntaxhighlight lang="bqn">•file.Remove "input.txt" |
||
•file.Remove "/input.txt" |
•file.Remove "/input.txt" |
||
•file.RemoveDir "docs" |
•file.RemoveDir "docs" |
||
•file.RemoveDir "/docs"</ |
•file.RemoveDir "/docs"</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
ISO C: |
ISO C: |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
int main() { |
int main() { |
||
Line 409: | Line 409: | ||
remove("/docs"); |
remove("/docs"); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
POSIX: |
POSIX: |
||
< |
<syntaxhighlight lang="c">#include <unistd.h> |
||
int main() { |
int main() { |
||
Line 420: | Line 420: | ||
rmdir("/docs"); |
rmdir("/docs"); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.IO; |
using System.IO; |
||
Line 439: | Line 439: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <cstdio> |
||
#include <direct.h> |
#include <direct.h> |
||
Line 452: | Line 452: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="lisp">(import '(java.io File)) |
||
(.delete (File. "output.txt")) |
(.delete (File. "output.txt")) |
||
(.delete (File. "docs")) |
(.delete (File. "docs")) |
||
(.delete (new File (str (File/separator) "output.txt"))) |
(.delete (new File (str (File/separator) "output.txt"))) |
||
(.delete (new File (str (File/separator) "docs")))</ |
(.delete (new File (str (File/separator) "docs")))</syntaxhighlight> |
||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
Line 466: | Line 466: | ||
{{works with|Visual COBOL}} |
{{works with|Visual COBOL}} |
||
{{works with|OpenCOBOL}} |
{{works with|OpenCOBOL}} |
||
< |
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. |
||
PROGRAM-ID. Delete-Files. |
PROGRAM-ID. Delete-Files. |
||
Line 476: | Line 476: | ||
GOBACK |
GOBACK |
||
.</ |
.</syntaxhighlight> |
||
Alternate method of deleting files using the <code>DELETE FILE</code> statement. |
Alternate method of deleting files using the <code>DELETE FILE</code> statement. |
||
{{works with|Visual COBOL}} |
{{works with|Visual COBOL}} |
||
< |
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. |
||
PROGRAM-ID. Delete-Files-2. |
PROGRAM-ID. Delete-Files-2. |
||
Line 502: | Line 502: | ||
GOBACK |
GOBACK |
||
.</ |
.</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
< |
<syntaxhighlight lang="lisp">(delete-file (make-pathname :name "input.txt")) |
||
(delete-file (make-pathname :directory '(:absolute "") :name "input.txt"))</ |
(delete-file (make-pathname :directory '(:absolute "") :name "input.txt"))</syntaxhighlight> |
||
To delete directories we need an implementation specific extension. In clisp this is ''ext:delete-dir''. |
To delete directories we need an implementation specific extension. In clisp this is ''ext:delete-dir''. |
||
{{works with|CLISP}} |
{{works with|CLISP}} |
||
< |
<syntaxhighlight lang="lisp">(let ((path (make-pathname :directory '(:relative "docs")))) |
||
(ext:delete-dir path)) |
(ext:delete-dir path)) |
||
(let ((path (make-pathname :directory '(:absolute "docs")))) |
(let ((path (make-pathname :directory '(:absolute "docs")))) |
||
(ext:delete-dir path))</ |
(ext:delete-dir path))</syntaxhighlight> |
||
Or you can use the portability library CL-FAD: |
Or you can use the portability library CL-FAD: |
||
{{libheader|CL-FAD}} |
{{libheader|CL-FAD}} |
||
< |
<syntaxhighlight lang="lisp">(let ((path (make-pathname :directory '(:relative "docs")))) |
||
(cl-fad:delete-directory-and-files path))</ |
(cl-fad:delete-directory-and-files path))</syntaxhighlight> |
||
=={{header|Component Pascal}}== |
=={{header|Component Pascal}}== |
||
{{Works with|BlackBox Component Builder}} |
{{Works with|BlackBox Component Builder}} |
||
< |
<syntaxhighlight lang="oberon2"> |
||
VAR |
VAR |
||
l: Files.Locator; |
l: Files.Locator; |
||
Line 532: | Line 532: | ||
Files.dir.Delete(l,"xx.txt"); |
Files.dir.Delete(l,"xx.txt"); |
||
END ... |
END ... |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
{{works with|D|2}} |
{{works with|D|2}} |
||
< |
<syntaxhighlight lang="d">import std.file: remove; |
||
void main() { |
void main() { |
||
remove("data.txt"); |
remove("data.txt"); |
||
}</ |
}</syntaxhighlight> |
||
{{libheader|Tango}} |
{{libheader|Tango}} |
||
< |
<syntaxhighlight lang="d">import tango.io.Path; |
||
void main() { |
void main() { |
||
Line 549: | Line 549: | ||
remove("docs"); |
remove("docs"); |
||
remove("/docs"); |
remove("/docs"); |
||
}</ |
}</syntaxhighlight> |
||
{{libheader|Tango}} |
{{libheader|Tango}} |
||
POSIX: |
POSIX: |
||
< |
<syntaxhighlight lang="d">import tango.stdc.posix.unistd; |
||
void main() { |
void main() { |
||
Line 560: | Line 560: | ||
rmdir("docs"); |
rmdir("docs"); |
||
rmdir("/docs"); |
rmdir("/docs"); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
< |
<syntaxhighlight lang="e">procedure TMain.btnDeleteClick(Sender: TObject); |
||
var |
var |
||
CurrentDirectory : String; |
CurrentDirectory : String; |
||
Line 575: | Line 575: | ||
RmDir(PChar('c:\docs')); |
RmDir(PChar('c:\docs')); |
||
end; |
end; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|E}}== |
=={{header|E}}== |
||
< |
<syntaxhighlight lang="e"><file:input.txt>.delete(null) |
||
<file:docs>.delete(null) |
<file:docs>.delete(null) |
||
<file:///input.txt>.delete(null) |
<file:///input.txt>.delete(null) |
||
<file:///docs>.delete(null)</ |
<file:///docs>.delete(null)</syntaxhighlight> |
||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 4.x : |
ELENA 4.x : |
||
< |
<syntaxhighlight lang="elena">import system'io; |
||
public program() |
public program() |
||
Line 596: | Line 596: | ||
Directory.assign("\docs").delete(); |
Directory.assign("\docs").delete(); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
< |
<syntaxhighlight lang="elixir">File.rm!("input.txt") |
||
File.rmdir!("docs") |
File.rmdir!("docs") |
||
File.rm!("/input.txt") |
File.rm!("/input.txt") |
||
File.rmdir!("/docs")</ |
File.rmdir!("/docs")</syntaxhighlight> |
||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
< |
<syntaxhighlight lang="lisp">(delete-file "input.txt") |
||
(delete-directory "docs") |
(delete-directory "docs") |
||
(delete-file "/input.txt") |
(delete-file "/input.txt") |
||
(delete-directory "/docs")</ |
(delete-directory "/docs")</syntaxhighlight> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
< |
<syntaxhighlight lang="erlang"> |
||
-module(delete). |
-module(delete). |
||
-export([main/0]). |
-export([main/0]). |
||
Line 622: | Line 622: | ||
ok = file:del_dir( "/docs" ), |
ok = file:del_dir( "/docs" ), |
||
ok = file:delete( "/input.txt" ). |
ok = file:delete( "/input.txt" ). |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp">open System.IO |
||
[<EntryPoint>] |
[<EntryPoint>] |
||
Line 634: | Line 634: | ||
ignore (File.Delete(Path.Combine(path, fileName))) |
ignore (File.Delete(Path.Combine(path, fileName))) |
||
ignore (Directory.Delete(Path.Combine(path, dirName))) |
ignore (Directory.Delete(Path.Combine(path, dirName))) |
||
0</ |
0</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">"docs" "/docs" [ delete-tree ] bi@ |
||
"input.txt" "/input.txt" [ delete-file ] bi@</ |
"input.txt" "/input.txt" [ delete-file ] bi@</syntaxhighlight> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
There is no means to delete directories in ANS Forth. |
There is no means to delete directories in ANS Forth. |
||
< |
<syntaxhighlight lang="forth"> s" input.txt" delete-file throw |
||
s" /input.txt" delete-file throw</ |
s" /input.txt" delete-file throw</syntaxhighlight> |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Line 649: | Line 649: | ||
{{works with|Fortran|90 and later}} |
{{works with|Fortran|90 and later}} |
||
< |
<syntaxhighlight 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")</syntaxhighlight> |
||
=== Intel Fortran on Windows === |
=== Intel Fortran on Windows === |
||
Use Intel Fortran bindings to the Win32 API. Here we are using the [https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea DeleteFileA] and [https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya RemoveDirectoryA] functions. |
Use Intel Fortran bindings to the Win32 API. Here we are using the [https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea DeleteFileA] and [https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya RemoveDirectoryA] functions. |
||
< |
<syntaxhighlight lang="fortran">program DeleteFileExample |
||
use kernel32 |
use kernel32 |
||
implicit none |
implicit none |
||
Line 664: | Line 664: | ||
print *, RemoveDirectory("docs") |
print *, RemoveDirectory("docs") |
||
print *, RemoveDirectory("\docs") |
print *, RemoveDirectory("\docs") |
||
end program</ |
end program</syntaxhighlight> |
||
=={{header|Free Pascal}}== |
=={{header|Free Pascal}}== |
||
All required functions already exist in the RTL’s (run-time library) <code>system</code> unit which is shipped with every FPC (Free Pascal compiler) distribution and automatically included by every program. |
All required functions already exist in the RTL’s (run-time library) <code>system</code> unit which is shipped with every FPC (Free Pascal compiler) distribution and automatically included by every program. |
||
< |
<syntaxhighlight lang="pascal">program deletion(input, output, stdErr); |
||
const |
const |
||
rootDirectory = '/'; // might have to be altered for other platforms |
rootDirectory = '/'; // might have to be altered for other platforms |
||
Line 685: | Line 685: | ||
rmDir(rootDirectory + docsFilename); |
rmDir(rootDirectory + docsFilename); |
||
end.</ |
end.</syntaxhighlight> |
||
Note, depending on the <code>{$IOChecks}</code> compiler switch state, run-time error generation is inserted. |
Note, depending on the <code>{$IOChecks}</code> compiler switch state, run-time error generation is inserted. |
||
In particular deletion of non-existent files or lack of privileges may cause an abort. |
In particular deletion of non-existent files or lack of privileges may cause an abort. |
||
Line 693: | Line 693: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64 |
||
' delete file and empty sub-directory in current directory |
' delete file and empty sub-directory in current directory |
||
Line 708: | Line 708: | ||
Print "Press any key to quit" |
Print "Press any key to quit" |
||
Sleep |
Sleep |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Furor}}== |
=={{header|Furor}}== |
||
<syntaxhighlight lang="furor"> |
|||
<lang Furor> |
|||
###sysinclude dir.uh |
###sysinclude dir.uh |
||
// =================== |
// =================== |
||
Line 718: | Line 718: | ||
2 argv removefile |
2 argv removefile |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Usage: furor removefile.upu filename |
Usage: furor removefile.upu filename |
||
</pre> |
</pre> |
||
<syntaxhighlight lang="furor"> |
|||
<lang Furor> |
|||
###sysinclude dir.uh |
###sysinclude dir.uh |
||
#g argc 3 < { ."Usage: " #s 0 argv print SPACE 1 argv print SPACE ."unnecessary_directory\n" end } |
#g argc 3 < { ."Usage: " #s 0 argv print SPACE 1 argv print SPACE ."unnecessary_directory\n" end } |
||
Line 730: | Line 730: | ||
} |
} |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Usage: furor rmdir.upu unnecessary_directory |
Usage: furor rmdir.upu unnecessary_directory |
||
Line 738: | Line 738: | ||
=={{header|Gambas}}== |
=={{header|Gambas}}== |
||
< |
<syntaxhighlight lang="gambas">Public Sub Main() |
||
Kill User.home &/ "input.txt" |
Kill User.home &/ "input.txt" |
||
Line 745: | Line 745: | ||
'Administrative privileges (sudo) would be required to mess about in Root - I'm not going there! |
'Administrative privileges (sudo) would be required to mess about in Root - I'm not going there! |
||
End</ |
End</syntaxhighlight> |
||
=={{header|GAP}}== |
=={{header|GAP}}== |
||
< |
<syntaxhighlight lang="gap"># Apparently GAP can only remove a file, not a directory |
||
RemoveFile("input.txt"); |
RemoveFile("input.txt"); |
||
# true |
# true |
||
RemoveFile("docs"); |
RemoveFile("docs"); |
||
# fail</ |
# fail</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import "os" |
import "os" |
||
Line 766: | Line 766: | ||
os.RemoveAll("docs") |
os.RemoveAll("docs") |
||
os.RemoveAll("/docs") |
os.RemoveAll("/docs") |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
On most *nix systems, this must be run as sudo for the files in root to be deleted. If you don't have permissions, it will silently fail to delete those files. I would recommend against running anything you find on the internet as sudo. |
On most *nix systems, this must be run as sudo for the files in root to be deleted. If you don't have permissions, it will silently fail to delete those files. I would recommend against running anything you find on the internet as sudo. |
||
< |
<syntaxhighlight lang="groovy">// Gets the first filesystem root. On most systems this will be / or c:\ |
||
def fsRoot = File.listRoots().first() |
def fsRoot = File.listRoots().first() |
||
Line 788: | Line 788: | ||
files.each{ |
files.each{ |
||
it.directory ? it.deleteDir() : it.delete() |
it.directory ? it.deleteDir() : it.delete() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import System.IO |
||
import System.Directory |
import System.Directory |
||
Line 799: | Line 799: | ||
removeDirectory "docs" |
removeDirectory "docs" |
||
removeFile "/output.txt" |
removeFile "/output.txt" |
||
removeDirectory "/docs"</ |
removeDirectory "/docs"</syntaxhighlight> |
||
=={{header|HicEst}}== |
=={{header|HicEst}}== |
||
< |
<syntaxhighlight lang="hicest">SYSTEM(DIR="docs") ! create docs in current directory (if not existent), make it current |
||
OPEN (FILE="input.txt", "NEW") ! in current directory = docs |
OPEN (FILE="input.txt", "NEW") ! in current directory = docs |
||
WRITE(FIle="input.txt", DELETE=1) ! no command to DELETE a DIRECTORY in HicEst |
WRITE(FIle="input.txt", DELETE=1) ! no command to DELETE a DIRECTORY in HicEst |
||
Line 808: | Line 808: | ||
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="input.txt", "NEW") ! in current directory = C:\docs |
OPEN (FILE="input.txt", "NEW") ! in current directory = C:\docs |
||
WRITE(FIle="input.txt", DELETE=1)</ |
WRITE(FIle="input.txt", DELETE=1)</syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
Icon supports 'remove' for files. |
Icon supports 'remove' for files. |
||
< |
<syntaxhighlight lang="unicon">every dir := !["./","/"] do { |
||
remove(f := dir || "input.txt") |stop("failure for file remove ",f) |
remove(f := dir || "input.txt") |stop("failure for file remove ",f) |
||
rmdir(f := dir || "docs") |stop("failure for directory remove ",f) |
rmdir(f := dir || "docs") |stop("failure for directory remove ",f) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Note Icon and Unicon accept both / and \ for directory separators. |
Note Icon and Unicon accept both / and \ for directory separators. |
||
=={{header|Io}}== |
=={{header|Io}}== |
||
< |
<syntaxhighlight 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</syntaxhighlight> |
||
or |
or |
||
< |
<syntaxhighlight lang="io">File with("input.txt") remove |
||
Directory with("docs") remove |
Directory with("docs") remove |
||
File with("/input.txt") remove |
File with("/input.txt") remove |
||
Directory with("/docs") remove</ |
Directory with("/docs") remove</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
The J standard library comes with a set of file access utilities. |
The J standard library comes with a set of file access utilities. |
||
< |
<syntaxhighlight lang="j"> load 'files' |
||
ferase 'input.txt' |
ferase 'input.txt' |
||
ferase '\input.txt' |
ferase '\input.txt' |
||
Line 841: | Line 841: | ||
NB. Or all at once... |
NB. Or all at once... |
||
ferase 'input.txt';'/input.txt';'docs';'/docs'</ |
ferase 'input.txt';'/input.txt';'docs';'/docs'</syntaxhighlight> |
||
The function above actually uses a foreign conjunction and defined in the <tt>files</tt> library like so: |
The function above actually uses a foreign conjunction and defined in the <tt>files</tt> library like so: |
||
< |
<syntaxhighlight lang="j">NB. ========================================================= |
||
NB.*ferase v erases a file |
NB.*ferase v erases a file |
||
NB. Returns 1 if successful, otherwise _1 |
NB. Returns 1 if successful, otherwise _1 |
||
ferase=: (1!:55 :: _1:) @ (fboxname &>) @ boxopen</ |
ferase=: (1!:55 :: _1:) @ (fboxname &>) @ boxopen</syntaxhighlight> |
||
This means that you can directly erase files and directories without loading the <tt>files</tt> library. |
This means that you can directly erase files and directories without loading the <tt>files</tt> library. |
||
< |
<syntaxhighlight lang="j">1!:55 <'input.txt' |
||
1!:55 <'\input.txt' |
1!:55 <'\input.txt' |
||
1!:55 <'docs' |
1!:55 <'docs' |
||
1!:55 <'\docs'</ |
1!:55 <'\docs'</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">import java.io.File; |
||
public class FileDeleteTest { |
public class FileDeleteTest { |
||
Line 877: | Line 877: | ||
test("directory", File.seperator + "docs" + File.seperator); |
test("directory", File.seperator + "docs" + File.seperator); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
{{works with|JScript}} |
{{works with|JScript}} |
||
< |
<syntaxhighlight lang="javascript">var fso = new ActiveXObject("Scripting.FileSystemObject"); |
||
fso.DeleteFile('input.txt'); |
fso.DeleteFile('input.txt'); |
||
Line 887: | Line 887: | ||
fso.DeleteFolder('docs'); |
fso.DeleteFolder('docs'); |
||
fso.DeleteFolder('c:/docs');</ |
fso.DeleteFolder('c:/docs');</syntaxhighlight> |
||
or |
or |
||
< |
<syntaxhighlight lang="javascript">var fso = new ActiveXObject("Scripting.FileSystemObject"); |
||
var f; |
var f; |
||
f = fso.GetFile('input.txt'); |
f = fso.GetFile('input.txt'); |
||
Line 900: | Line 900: | ||
f.Delete(); |
f.Delete(); |
||
f = fso.GetFolder('c:/docs'); |
f = fso.GetFolder('c:/docs'); |
||
f.Delete();</ |
f.Delete();</syntaxhighlight> |
||
{{works with|Node.js}} |
{{works with|Node.js}} |
||
Synchronous |
Synchronous |
||
< |
<syntaxhighlight lang="javascript">const fs = require('fs'); |
||
fs.unlinkSync('myfile.txt');</ |
fs.unlinkSync('myfile.txt');</syntaxhighlight> |
||
Asynchronous |
Asynchronous |
||
< |
<syntaxhighlight lang="javascript">const fs = require('fs'); |
||
fs.unlink('myfile.txt', ()=>{ |
fs.unlink('myfile.txt', ()=>{ |
||
console.log("Done!"); |
console.log("Done!"); |
||
})</ |
})</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia"> |
||
# Delete a file |
# Delete a file |
||
rm("input.txt") |
rm("input.txt") |
||
Line 919: | Line 919: | ||
# Delete a directory |
# Delete a directory |
||
rm("docs", recursive = true) |
rm("docs", recursive = true) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// version 1.0.6 |
||
/* testing on Windows 10 which needs administrative privileges |
/* testing on Windows 10 which needs administrative privileges |
||
Line 939: | Line 939: | ||
println("$path could not be deleted") |
println("$path could not be deleted") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 962: | Line 962: | ||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang="lasso">// delete file |
||
local(f = file('input.txt')) |
local(f = file('input.txt')) |
||
#f->delete |
#f->delete |
||
Line 978: | Line 978: | ||
// directory must be empty before it can be successfully deleted. A failure is generated if the operation fails. |
// directory must be empty before it can be successfully deleted. A failure is generated if the operation fails. |
||
local(d = file('//docs')) |
local(d = file('//docs')) |
||
#d->delete</ |
#d->delete</syntaxhighlight> |
||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
< |
<syntaxhighlight lang="lb">' show where we are |
||
print DefaultDir$ |
print DefaultDir$ |
||
Line 991: | Line 991: | ||
kill "\input.txt" |
kill "\input.txt" |
||
result=rmdir("\Docs") |
result=rmdir("\Docs") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Lingo}}== |
=={{header|Lingo}}== |
||
Delete file "input.txt" in cwd: |
Delete file "input.txt" in cwd: |
||
< |
<syntaxhighlight lang="lingo">-- note: fileIO xtra is shipped with Director, i.e. an "internal" |
||
fp = xtra("fileIO").new() |
fp = xtra("fileIO").new() |
||
fp.openFile("input.txt", 0) |
fp.openFile("input.txt", 0) |
||
fp.delete()</ |
fp.delete()</syntaxhighlight> |
||
Delete file "input.txt" in root of current volume: |
Delete file "input.txt" in root of current volume: |
||
< |
<syntaxhighlight lang="lingo">-- note: fileIO xtra is shipped with Director, i.e. an "internal" |
||
pd = the last char of _movie.path -- "\" for win, ":" for mac |
pd = the last char of _movie.path -- "\" for win, ":" for mac |
||
_player.itemDelimiter = pd |
_player.itemDelimiter = pd |
||
Line 1,008: | Line 1,008: | ||
fp = xtra("fileIO").new() |
fp = xtra("fileIO").new() |
||
fp.openFile(vol&pd&"input.txt", 0) |
fp.openFile(vol&pd&"input.txt", 0) |
||
fp.delete()</ |
fp.delete()</syntaxhighlight> |
||
Deleting a directory requires a 3rd party xtra, but there are various free xtras that allow this. Here as example usage of BinFile xtra: |
Deleting a directory requires a 3rd party xtra, but there are various free xtras that allow this. Here as example usage of BinFile xtra: |
||
< |
<syntaxhighlight lang="lingo">-- delete (empty) directory "docs" in cwd |
||
bx_folder_delete("docs") |
bx_folder_delete("docs") |
||
Line 1,019: | Line 1,019: | ||
_player.itemDelimiter = pd |
_player.itemDelimiter = pd |
||
vol = _movie.path.item[1] |
vol = _movie.path.item[1] |
||
bx_folder_delete(vol&pd&"docs")</ |
bx_folder_delete(vol&pd&"docs")</syntaxhighlight> |
||
=={{header|Locomotive Basic}}== |
=={{header|Locomotive Basic}}== |
||
< |
<syntaxhighlight lang="locobasic">|era,"input.txt"</syntaxhighlight> |
||
([[wp:AMSDOS|AMSDOS]] RSX command, therefore prefixed with a vertical bar. Also, there are no subdirectories in AMSDOS.) |
([[wp:AMSDOS|AMSDOS]] RSX command, therefore prefixed with a vertical bar. Also, there are no subdirectories in AMSDOS.) |
||
Line 1,029: | Line 1,029: | ||
{{works with|UCB Logo}} |
{{works with|UCB Logo}} |
||
UCB Logo has no means to delete directories. |
UCB Logo has no means to delete directories. |
||
< |
<syntaxhighlight lang="logo">erasefile "input.txt |
||
erasefile "/input.txt</ |
erasefile "/input.txt</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang="lua">os.remove("input.txt") |
||
os.remove("/input.txt") |
os.remove("/input.txt") |
||
os.remove("docs") |
os.remove("docs") |
||
os.remove("/docs")</ |
os.remove("/docs")</syntaxhighlight> |
||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
< |
<syntaxhighlight lang="maple">FileTools:-Remove("input.txt"); |
||
FileTools:-RemoveDirectory("docs"); |
FileTools:-RemoveDirectory("docs"); |
||
FileTools:-Remove("/input.txt"); |
FileTools:-Remove("/input.txt"); |
||
FileTools:-RemoveDirectory("/docs"); |
FileTools:-RemoveDirectory("/docs"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">wd = NotebookDirectory[]; |
||
DeleteFile[wd <> "input.txt"] |
DeleteFile[wd <> "input.txt"] |
||
DeleteFile["/" <> "input.txt"] |
DeleteFile["/" <> "input.txt"] |
||
DeleteDirectory[wd <> "docs"] |
DeleteDirectory[wd <> "docs"] |
||
DeleteDirectory["/" <> "docs"]</ |
DeleteDirectory["/" <> "docs"]</syntaxhighlight> |
||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
< |
<syntaxhighlight lang="matlab"> delete('input.txt'); % delete local file input.txt |
||
delete('/input.txt'); % delete file /input.txt |
delete('/input.txt'); % delete file /input.txt |
||
rmdir('docs'); % remove local directory docs |
rmdir('docs'); % remove local directory docs |
||
rmdir('/docs'); % remove directory /docs |
rmdir('/docs'); % remove directory /docs |
||
</ |
</syntaxhighlight> |
||
On Unix-Systems: |
On Unix-Systems: |
||
< |
<syntaxhighlight lang="matlab">if system('rm input.txt') == 0 |
||
disp('input.txt removed') |
disp('input.txt removed') |
||
end |
end |
||
Line 1,072: | Line 1,072: | ||
if system('rmdir /docs') == 0 |
if system('rmdir /docs') == 0 |
||
disp('/docs removed') |
disp('/docs removed') |
||
end</ |
end</syntaxhighlight> |
||
=={{header|MAXScript}}== |
=={{header|MAXScript}}== |
||
There's no way to delete folders in MAXScript |
There's no way to delete folders in MAXScript |
||
< |
<syntaxhighlight lang="maxscript">-- Here |
||
deleteFile "input.txt" |
deleteFile "input.txt" |
||
-- Root |
-- Root |
||
deleteFile "\input.txt"</ |
deleteFile "\input.txt"</syntaxhighlight> |
||
=={{header|Mercury}}== |
=={{header|Mercury}}== |
||
< |
<syntaxhighlight lang="mercury">:- module delete_file. |
||
:- interface. |
:- interface. |
||
Line 1,095: | Line 1,095: | ||
io.remove_file("/input.txt", _, !IO), |
io.remove_file("/input.txt", _, !IO), |
||
io.remove_file("docs", _, !IO), |
io.remove_file("docs", _, !IO), |
||
io.remove_file("/docs", _, !IO).</ |
io.remove_file("/docs", _, !IO).</syntaxhighlight> |
||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
{{trans|Ursa}} |
{{trans|Ursa}} |
||
< |
<syntaxhighlight lang="nanoquery">f = new(Nanoquery.IO.File) |
||
f.delete("input.txt") |
f.delete("input.txt") |
||
f.delete("docs") |
f.delete("docs") |
||
f.delete("/input.txt") |
f.delete("/input.txt") |
||
f.delete("/docs")</ |
f.delete("/docs")</syntaxhighlight> |
||
=={{header|Nemerle}}== |
=={{header|Nemerle}}== |
||
< |
<syntaxhighlight lang="nemerle">using System; |
||
using System.IO; |
using System.IO; |
||
using System.Console; |
using System.Console; |
||
Line 1,125: | Line 1,125: | ||
when (Directory.Exists(@"\docs")) Directory.Delete(@"\docs"); |
when (Directory.Exists(@"\docs")) Directory.Delete(@"\docs"); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |
||
< |
<syntaxhighlight lang="netrexx">/* NetRexx */ |
||
options replace format comments java crossref symbols binary |
options replace format comments java crossref symbols binary |
||
Line 1,163: | Line 1,163: | ||
return |
return |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|NewLISP}}== |
=={{header|NewLISP}}== |
||
< |
<syntaxhighlight lang="newlisp">(delete-file "input.txt") |
||
(delete-file "/input.txt") |
(delete-file "/input.txt") |
||
(remove-dir "docs") |
(remove-dir "docs") |
||
(remove-dir "/docs")</ |
(remove-dir "/docs")</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import os |
||
removeFile("input.txt") |
removeFile("input.txt") |
||
removeFile("/input.txt") |
removeFile("/input.txt") |
||
removeDir("docs") |
removeDir("docs") |
||
removeDir("/docs")</ |
removeDir("/docs")</syntaxhighlight> |
||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
< |
<syntaxhighlight lang="objeck"> |
||
use IO; |
use IO; |
||
Line 1,193: | Line 1,193: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |
||
< |
<syntaxhighlight lang="objc">NSFileManager *fm = [NSFileManager defaultManager]; |
||
// Pre-OS X 10.5 |
// Pre-OS X 10.5 |
||
Line 1,209: | Line 1,209: | ||
[fm removeItemAtPath:@"/input.txt" error:NULL]; |
[fm removeItemAtPath:@"/input.txt" error:NULL]; |
||
[fm removeItemAtPath:@"docs" error:NULL]; |
[fm removeItemAtPath:@"docs" error:NULL]; |
||
[fm removeItemAtPath:@"/docs" error:NULL];</ |
[fm removeItemAtPath:@"/docs" error:NULL];</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang="ocaml">Sys.remove "input.txt";; |
||
Sys.remove "/input.txt";;</ |
Sys.remove "/input.txt";;</syntaxhighlight> |
||
with the Unix library: |
with the Unix library: |
||
< |
<syntaxhighlight lang="ocaml">#load "unix.cma";; |
||
Unix.unlink "input.txt";; |
Unix.unlink "input.txt";; |
||
Unix.unlink "/input.txt";; |
Unix.unlink "/input.txt";; |
||
Unix.rmdir "docs";; |
Unix.rmdir "docs";; |
||
Unix.rmdir "/docs";;</ |
Unix.rmdir "/docs";;</syntaxhighlight> |
||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
< |
<syntaxhighlight lang="oorexx">/*REXX pgm deletes a file */ |
||
file= 'afile.txt' /*name of a file to be deleted.*/ |
file= 'afile.txt' /*name of a file to be deleted.*/ |
||
res=sysFileDelete(file); Say file 'res='res |
res=sysFileDelete(file); Say file 'res='res |
||
File= 'bfile.txt' /*name of a file to be deleted.*/ |
File= 'bfile.txt' /*name of a file to be deleted.*/ |
||
res=sysFileDelete(file); Say file 'res='res</ |
res=sysFileDelete(file); Say file 'res='res</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>afile.txt res=0 |
<pre>afile.txt res=0 |
||
Line 1,234: | Line 1,234: | ||
=={{header|Oz}}== |
=={{header|Oz}}== |
||
< |
<syntaxhighlight lang="oz">for Dir in ["/" "./"] do |
||
try {OS.unlink Dir#"output.txt"} |
try {OS.unlink Dir#"output.txt"} |
||
catch _ then {System.showInfo "File does not exist."} end |
catch _ then {System.showInfo "File does not exist."} end |
||
try {OS.rmDir Dir#"docs"} |
try {OS.rmDir Dir#"docs"} |
||
catch _ then {System.showInfo "Directory does not exist."} end |
catch _ then {System.showInfo "Directory does not exist."} end |
||
end</ |
end</syntaxhighlight> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
GP has no built-in facilities for deleting files, but can use a system call: |
GP has no built-in facilities for deleting files, but can use a system call: |
||
< |
<syntaxhighlight lang="parigp">system("rm -rf docs"); |
||
system("rm input.txt"); |
system("rm input.txt"); |
||
system("rm -rf /docs"); |
system("rm -rf /docs"); |
||
system("rm /input.txt");</ |
system("rm /input.txt");</syntaxhighlight> |
||
PARI, as usual, has access to all the standard [[#C|C]] methods. |
PARI, as usual, has access to all the standard [[#C|C]] methods. |
||
Line 1,254: | Line 1,254: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">use File::Spec::Functions qw(catfile rootdir); |
||
# here |
# here |
||
unlink 'input.txt'; |
unlink 'input.txt'; |
||
Line 1,260: | Line 1,260: | ||
# root dir |
# root dir |
||
unlink catfile rootdir, 'input.txt'; |
unlink catfile rootdir, 'input.txt'; |
||
rmdir catfile rootdir, 'docs';</ |
rmdir catfile rootdir, 'docs';</syntaxhighlight> |
||
'''Without Perl Modules''' |
'''Without Perl Modules''' |
||
Line 1,273: | Line 1,273: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(notonline)--> |
||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span> |
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">root</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">LINUX</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"/"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"C:\\"</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">root</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">LINUX</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"/"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"C:\\"</span><span style="color: #0000FF;">)</span> |
||
Line 1,280: | Line 1,280: | ||
<span style="color: #0000FF;">?</span><span style="color: #000000;">remove_directory</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"docs"</span><span style="color: #0000FF;">)</span> |
<span style="color: #0000FF;">?</span><span style="color: #000000;">remove_directory</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"docs"</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #0000FF;">?</span><span style="color: #000000;">remove_directory</span><span style="color: #0000FF;">(</span><span style="color: #000000;">root</span><span style="color: #0000FF;">&</span><span style="color: #008000;">"docs"</span><span style="color: #0000FF;">)</span> |
<span style="color: #0000FF;">?</span><span style="color: #000000;">remove_directory</span><span style="color: #0000FF;">(</span><span style="color: #000000;">root</span><span style="color: #0000FF;">&</span><span style="color: #008000;">"docs"</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
output is 0 0 0 0 or 1 1 1 1 or some combination thereof |
output is 0 0 0 0 or 1 1 1 1 or some combination thereof |
||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
< |
<syntaxhighlight lang="php"><?php |
||
unlink('input.txt'); |
unlink('input.txt'); |
||
unlink('/input.txt'); |
unlink('/input.txt'); |
||
rmdir('docs'); |
rmdir('docs'); |
||
rmdir('/docs'); |
rmdir('/docs'); |
||
?></ |
?></syntaxhighlight> |
||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
{{works with|Picat}} |
{{works with|Picat}} |
||
<syntaxhighlight lang="picat"> |
|||
<lang Picat> |
|||
import os. |
import os. |
||
Line 1,306: | Line 1,306: | ||
del(Arg) |
del(Arg) |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,313: | Line 1,313: | ||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(call 'rm "input.txt") |
||
(call 'rmdir "docs") |
(call 'rmdir "docs") |
||
(call 'rm "/input.txt") |
(call 'rm "/input.txt") |
||
(call 'rmdir "/docs")</ |
(call 'rmdir "/docs")</syntaxhighlight> |
||
=={{header|Pike}}== |
=={{header|Pike}}== |
||
< |
<syntaxhighlight lang="pike">int main(){ |
||
rm("input.txt"); |
rm("input.txt"); |
||
rm("/input.txt"); |
rm("/input.txt"); |
||
rm("docs"); |
rm("docs"); |
||
rm("/docs"); |
rm("/docs"); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
< |
<syntaxhighlight lang="powershell"># possible aliases for Remove-Item: rm, del, ri |
||
Remove-Item input.txt |
Remove-Item input.txt |
||
Remove-Item \input.txt # file system root |
Remove-Item \input.txt # file system root |
||
Remove-Item -Recurse docs # recurse for deleting folders including content |
Remove-Item -Recurse docs # recurse for deleting folders including content |
||
Remove-Item -Recurse \docs</ |
Remove-Item -Recurse \docs</syntaxhighlight> |
||
=={{header|ProDOS}}== |
=={{header|ProDOS}}== |
||
Because input.txt is located inside of "docs" this will delete it when it deletes "docs" |
Because input.txt is located inside of "docs" this will delete it when it deletes "docs" |
||
<lang |
<syntaxhighlight lang="prodos">deletedirectory docs</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">DeleteFile("input.txt") |
||
DeleteDirectory("docs","") ; needs to delete all included files |
DeleteDirectory("docs","") ; needs to delete all included files |
||
DeleteFile("/input.txt") |
DeleteFile("/input.txt") |
||
DeleteDirectory("/docs","*.*") ; deletes all files according to a pattern |
DeleteDirectory("/docs","*.*") ; deletes all files according to a pattern |
||
DeleteDirectory("/docs","",#PB_FileSystem_Recursive) ; deletes all files and directories recursive</ |
DeleteDirectory("/docs","",#PB_FileSystem_Recursive) ; deletes all files and directories recursive</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">import os |
||
# current directory |
# current directory |
||
os.remove("output.txt") |
os.remove("output.txt") |
||
Line 1,354: | Line 1,354: | ||
# root directory |
# root directory |
||
os.remove("/output.txt") |
os.remove("/output.txt") |
||
os.rmdir("/docs")</ |
os.rmdir("/docs")</syntaxhighlight> |
||
If you wanted to remove a directory and all its contents, recursively, you would do: |
If you wanted to remove a directory and all its contents, recursively, you would do: |
||
< |
<syntaxhighlight lang="python">import shutil |
||
shutil.rmtree("docs")</ |
shutil.rmtree("docs")</syntaxhighlight> |
||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<syntaxhighlight lang="r">file.remove("input.txt") |
||
file.remove("/input.txt") |
file.remove("/input.txt") |
||
Line 1,371: | Line 1,371: | ||
# directories needs the recursive flag |
# directories needs the recursive flag |
||
unlink("docs", recursive = TRUE) |
unlink("docs", recursive = TRUE) |
||
unlink("/docs", recursive = TRUE)</ |
unlink("/docs", recursive = TRUE)</syntaxhighlight> |
||
The function <tt>unlink</tt> allows wildcards (* and ?) |
The function <tt>unlink</tt> allows wildcards (* and ?) |
||
Line 1,377: | Line 1,377: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<syntaxhighlight lang="racket"> |
|||
<lang Racket> |
|||
#lang racket |
#lang racket |
||
Line 1,395: | Line 1,395: | ||
(delete-directory "docs") |
(delete-directory "docs") |
||
(delete-directory/files "docs")) |
(delete-directory/files "docs")) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>unlink 'input.txt'; |
||
unlink '/input.txt'; |
unlink '/input.txt'; |
||
rmdir 'docs'; |
rmdir 'docs'; |
||
rmdir '/docs';</ |
rmdir '/docs';</syntaxhighlight> |
||
=={{header|Raven}}== |
=={{header|Raven}}== |
||
< |
<syntaxhighlight lang="raven">'input.txt' delete |
||
'/input.txt' delete |
'/input.txt' delete |
||
'docs' rmdir |
'docs' rmdir |
||
'/docs' rmdir</ |
'/docs' rmdir</syntaxhighlight> |
||
=={{header|REBOL}}== |
=={{header|REBOL}}== |
||
< |
<syntaxhighlight lang="rebol">; Local. |
||
delete %input.txt |
delete %input.txt |
||
delete-dir %docs/ |
delete-dir %docs/ |
||
Line 1,418: | Line 1,418: | ||
; Root. |
; Root. |
||
delete %/input.txt |
delete %/input.txt |
||
delete-dir %/docs/</ |
delete-dir %/docs/</syntaxhighlight> |
||
=={{header|Retro}}== |
=={{header|Retro}}== |
||
< |
<syntaxhighlight lang="retro">'input.txt file:delete |
||
'/input.txt file:delete</ |
'/input.txt file:delete</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Note that this REXX program will work on the Next family of Microsoft Windows systems as well as DOS (both under Windows in a DOS-prompt window or stand-alone DOS). |
Note that this REXX program will work on the Next family of Microsoft Windows systems as well as DOS (both under Windows in a DOS-prompt window or stand-alone DOS). |
||
< |
<syntaxhighlight lang="rexx">/*REXX program deletes a file and a folder in the current directory and the root. */ |
||
trace off /*suppress REXX error messages from DOS*/ |
trace off /*suppress REXX error messages from DOS*/ |
||
aFile= 'input.txt' /*name of a file to be deleted. */ |
aFile= 'input.txt' /*name of a file to be deleted. */ |
||
Line 1,435: | Line 1,435: | ||
if j==1 then 'CD \' /*make the current dir the root dir.*/ |
if j==1 then 'CD \' /*make the current dir the root dir.*/ |
||
end /* [↑] just do CD \ command once.*/ |
end /* [↑] just do CD \ command once.*/ |
||
/*stick a fork in it, we're all done. */</ |
/*stick a fork in it, we're all done. */</syntaxhighlight> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
remove("output.txt") |
remove("output.txt") |
||
system("rmdir docs") |
system("rmdir docs") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">File.delete("output.txt", "/output.txt") |
||
Dir.delete("docs") |
Dir.delete("docs") |
||
Dir.delete("/docs")</ |
Dir.delete("/docs")</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
< |
<syntaxhighlight lang="runbasic">'------ delete input.txt ---------------- |
||
kill "input.txt" ' this is where we are |
kill "input.txt" ' this is where we are |
||
kill "/input.txt" ' this is the root |
kill "/input.txt" ' this is the root |
||
Line 1,457: | Line 1,457: | ||
' ---- delete directory docs ---------- |
' ---- delete directory docs ---------- |
||
result = rmdir("Docs") ' directory where we are |
result = rmdir("Docs") ' directory where we are |
||
result = rmdir("/Docs") ' root directory</ |
result = rmdir("/Docs") ' root directory</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">use std::io::{self, Write}; |
||
use std::fs::{remove_file,remove_dir}; |
use std::fs::{remove_file,remove_dir}; |
||
use std::path::Path; |
use std::path::Path; |
||
Line 1,484: | Line 1,484: | ||
let _ = writeln!(&mut io::stderr(), "{:?}", error); |
let _ = writeln!(&mut io::stderr(), "{:?}", error); |
||
process::exit(code) |
process::exit(code) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}} |
{{libheader|Scala}} |
||
< |
<syntaxhighlight lang="scala">import java.util._ |
||
import java.io.File |
import java.io.File |
||
Line 1,502: | Line 1,502: | ||
test("directory", "docs") |
test("directory", "docs") |
||
test("directory", File.separatorChar + "docs" + File.separatorChar) |
test("directory", File.separatorChar + "docs" + File.separatorChar) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
{{works with|Scheme|R6RS}}[http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-10.html] |
{{works with|Scheme|R6RS}}[http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-10.html] |
||
<lang |
<syntaxhighlight lang="scheme">(delete-file filename)</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
The library [http://seed7.sourceforge.net/libraries/osfiles.htm osfiles.s7i] provides the functions [http://seed7.sourceforge.net/libraries/osfiles.htm#removeFile%28in_string%29 removeFile] and [http://seed7.sourceforge.net/libraries/osfiles.htm#removeTree%28in_string%29 removeTree]. RemoveFile removes a file of any type unless it is a directory that is not empty. RemoveTree remove a file of any type inclusive a directory tree. Note that removeFile and removeTree fail with the exception [http://seed7.sourceforge.net/manual/errors.htm#FILE_ERROR FILE_ERROR] when the file does not exist. |
The library [http://seed7.sourceforge.net/libraries/osfiles.htm osfiles.s7i] provides the functions [http://seed7.sourceforge.net/libraries/osfiles.htm#removeFile%28in_string%29 removeFile] and [http://seed7.sourceforge.net/libraries/osfiles.htm#removeTree%28in_string%29 removeTree]. RemoveFile removes a file of any type unless it is a directory that is not empty. RemoveTree remove a file of any type inclusive a directory tree. Note that removeFile and removeTree fail with the exception [http://seed7.sourceforge.net/manual/errors.htm#FILE_ERROR FILE_ERROR] when the file does not exist. |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
include "osfiles.s7i"; |
include "osfiles.s7i"; |
||
Line 1,519: | Line 1,519: | ||
removeTree("docs"); |
removeTree("docs"); |
||
removeTree("/docs"); |
removeTree("/docs"); |
||
end func;</ |
end func;</syntaxhighlight> |
||
=={{header|SenseTalk}}== |
=={{header|SenseTalk}}== |
||
< |
<syntaxhighlight lang="sensetalk">// Delete locally (relative to "the folder") |
||
delete file "input.txt" |
delete file "input.txt" |
||
delete folder "docs" |
delete folder "docs" |
||
Line 1,529: | Line 1,529: | ||
delete file "/input.txt" |
delete file "/input.txt" |
||
delete folder "/docs" |
delete folder "/docs" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby"># here |
||
%f'input.txt' -> delete; |
%f'input.txt' -> delete; |
||
%d'docs' -> delete; |
%d'docs' -> delete; |
||
Line 1,538: | Line 1,538: | ||
# root dir |
# root dir |
||
Dir.root + %f'input.txt' -> delete; |
Dir.root + %f'input.txt' -> delete; |
||
Dir.root + %d'docs' -> delete;</ |
Dir.root + %d'docs' -> delete;</syntaxhighlight> |
||
=={{header|Slate}}== |
=={{header|Slate}}== |
||
Line 1,544: | Line 1,544: | ||
(It will succeed deleting the directory if it is empty) |
(It will succeed deleting the directory if it is empty) |
||
< |
<syntaxhighlight lang="slate">(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.</syntaxhighlight> |
||
Also: |
Also: |
||
< |
<syntaxhighlight lang="slate"> |
||
(Directory current / 'input.txt') delete. |
(Directory current / 'input.txt') delete. |
||
(Directory root / 'input.txt') delete.</ |
(Directory root / 'input.txt') delete.</syntaxhighlight> |
||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
Line 1,559: | Line 1,559: | ||
(It will succeed deleting the directory if it is empty) |
(It will succeed deleting the directory if it is empty) |
||
< |
<syntaxhighlight lang="smalltalk">File remove: 'input.txt'. |
||
File remove: 'docs'. |
File remove: 'docs'. |
||
File remove: '/input.txt'. |
File remove: '/input.txt'. |
||
File remove: '/docs'</ |
File remove: '/docs'</syntaxhighlight> |
||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |
||
< |
<syntaxhighlight lang="sml">OS.FileSys.remove "input.txt"; |
||
OS.FileSys.remove "/input.txt"; |
OS.FileSys.remove "/input.txt"; |
||
OS.FileSys.rmDir "docs"; |
OS.FileSys.rmDir "docs"; |
||
OS.FileSys.rmDir "/docs";</ |
OS.FileSys.rmDir "/docs";</syntaxhighlight> |
||
=={{header|Stata}}== |
=={{header|Stata}}== |
||
< |
<syntaxhighlight lang="stata">erase input.txt |
||
rmdir docs</ |
rmdir docs</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
< |
<syntaxhighlight lang="tcl">file delete input.txt /input.txt |
||
# preserve directory if non-empty |
# preserve directory if non-empty |
||
Line 1,583: | Line 1,583: | ||
# delete even if non-empty |
# delete even if non-empty |
||
file delete -force docs /docs</ |
file delete -force docs /docs</syntaxhighlight> |
||
=={{header|Toka}}== |
=={{header|Toka}}== |
||
< |
<syntaxhighlight lang="toka">needs shell |
||
" docs" remove |
" docs" remove |
||
" input.txt" remove</ |
" input.txt" remove</syntaxhighlight> |
||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
< |
<syntaxhighlight lang="tuscript"> |
||
$$ MODE TUSCRIPT |
$$ MODE TUSCRIPT |
||
- delete file |
- delete file |
||
Line 1,598: | Line 1,598: | ||
- delete directory |
- delete directory |
||
SET status = DELETE ("docs",-std-) |
SET status = DELETE ("docs",-std-) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
< |
<syntaxhighlight lang="bash">rm -rf docs |
||
rm input.txt |
rm input.txt |
||
rm -rf /docs |
rm -rf /docs |
||
rm /input.txt</ |
rm /input.txt</syntaxhighlight> |
||
=={{header|Ursa}}== |
=={{header|Ursa}}== |
||
< |
<syntaxhighlight lang="ursa">decl file f |
||
f.delete "input.txt" |
f.delete "input.txt" |
||
f.delete "docs" |
f.delete "docs" |
||
f.delete "/input.txt" |
f.delete "/input.txt" |
||
f.delete "/docs"</ |
f.delete "/docs"</syntaxhighlight> |
||
=={{header|VAX Assembly}}== |
=={{header|VAX Assembly}}== |
||
< |
<syntaxhighlight lang="vax assembly">74 75 70 6E 69 20 65 74 65 6C 65 64 0000 1 dcl: .ascii "delete input.txt;,docs.dir;" |
||
64 2E 73 63 6F 64 2C 3B 74 78 74 2E 000C |
64 2E 73 63 6F 64 2C 3B 74 78 74 2E 000C |
||
3B 72 69 0018 |
3B 72 69 0018 |
||
Line 1,633: | Line 1,633: | ||
0071 12 .end main |
0071 12 .end main |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|VBA}}== |
=={{header|VBA}}== |
||
< |
<syntaxhighlight lang="vb">Option Explicit |
||
Sub DeleteFileOrDirectory() |
Sub DeleteFileOrDirectory() |
||
Line 1,645: | Line 1,645: | ||
'delete Directory |
'delete Directory |
||
RmDir myPath |
RmDir myPath |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
< |
<syntaxhighlight lang="vb">Set oFSO = CreateObject( "Scripting.FileSystemObject" ) |
||
oFSO.DeleteFile "input.txt" |
oFSO.DeleteFile "input.txt" |
||
Line 1,670: | Line 1,670: | ||
fld.Delete |
fld.Delete |
||
</syntaxhighlight> |
|||
</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. |
||
< |
<syntaxhighlight lang="vedit">// In current directory |
||
File_Delete("input.txt", OK) |
File_Delete("input.txt", OK) |
||
File_Rmdir("docs") |
File_Rmdir("docs") |
||
Line 1,680: | Line 1,680: | ||
// In the root directory |
// In the root directory |
||
File_Delete("/input.txt", OK) |
File_Delete("/input.txt", OK) |
||
File_Rmdir("/docs")</ |
File_Rmdir("/docs")</syntaxhighlight> |
||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
Line 1,686: | Line 1,686: | ||
{{works with|Visual Basic .NET|9.0+}} |
{{works with|Visual Basic .NET|9.0+}} |
||
< |
<syntaxhighlight lang="vbnet">'Current Directory |
||
IO.Directory.Delete("docs") |
IO.Directory.Delete("docs") |
||
IO.Directory.Delete("docs", True) 'also delete files and sub-directories |
IO.Directory.Delete("docs", True) 'also delete files and sub-directories |
||
Line 1,697: | Line 1,697: | ||
'Root, platform independent |
'Root, platform independent |
||
IO.Directory.Delete(IO.Path.DirectorySeparatorChar & "docs") |
IO.Directory.Delete(IO.Path.DirectorySeparatorChar & "docs") |
||
IO.File.Delete(IO.Path.DirectorySeparatorChar & "output.txt")</ |
IO.File.Delete(IO.Path.DirectorySeparatorChar & "output.txt")</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 1,703: | Line 1,703: | ||
Wren does not currently support the removal of directories. |
Wren does not currently support the removal of directories. |
||
< |
<syntaxhighlight lang="ecmascript">import "io" for File |
||
File.delete("input.txt") |
File.delete("input.txt") |
||
// check it worked |
// check it worked |
||
System.print(File.exists("input.txt"))</ |
System.print(File.exists("input.txt"))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,718: | Line 1,718: | ||
{{works with|NASM|Linux}} |
{{works with|NASM|Linux}} |
||
< |
<syntaxhighlight lang="asm"> |
||
;syscall numbers for readability. :] |
;syscall numbers for readability. :] |
||
%define sys_rmdir 40 |
%define sys_rmdir 40 |
||
Line 1,764: | Line 1,764: | ||
err_msg db "Something went wrong! :[",0xa |
err_msg db "Something went wrong! :[",0xa |
||
err_len equ $-err_msg |
err_len equ $-err_msg |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Yorick}}== |
=={{header|Yorick}}== |
||
Yorick does not have a built-in function to recursively delete a directory; the rmdir function only works on empty directories. |
Yorick does not have a built-in function to recursively delete a directory; the rmdir function only works on empty directories. |
||
< |
<syntaxhighlight lang="yorick">remove, "input.txt"; |
||
remove, "/input.txt"; |
remove, "/input.txt"; |
||
rmdir, "docs"; |
rmdir, "docs"; |
||
rmdir, "/docs";</ |
rmdir, "/docs";</syntaxhighlight> |
||
=={{header|zig}}== |
=={{header|zig}}== |
||
< |
<syntaxhighlight lang="zig">const std = @import("std"); |
||
const fs = std.fs; |
const fs = std.fs; |
||
Line 1,786: | Line 1,786: | ||
try root.deleteFile("input.txt"); |
try root.deleteFile("input.txt"); |
||
try root.deleteDir("docs"); |
try root.deleteDir("docs"); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
zkl doesn't have built ins to delete files or directories but you can let a shell do it: |
zkl doesn't have built ins to delete files or directories but you can let a shell do it: |
||
< |
<syntaxhighlight lang="zkl">zkl: System.cmd((System.isWindows and "del" or "unlink") + " input.txt") |
||
0 |
0 |
||
zkl: System.cmd((System.isWindows and "del" or "unlink") + " /input.txt") |
zkl: System.cmd((System.isWindows and "del" or "unlink") + " /input.txt") |
||
Line 1,802: | Line 1,802: | ||
zkl: System.cmd("rm -r /docs") |
zkl: System.cmd("rm -r /docs") |
||
rm: cannot remove ‘/docs’: No such file or directory |
rm: cannot remove ‘/docs’: No such file or directory |
||
256</ |
256</syntaxhighlight> |
||
{{omit from|Befunge}} <!-- No filesystem support --> |
{{omit from|Befunge}} <!-- No filesystem support --> |