Delete a file: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Added solution for Action!)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(22 intermediate revisions by 16 users not shown)
Line 8:
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">fs:remove_file(‘output.txt’)
fs:remove_dir(‘docs’)
fs:remove_file(‘/output.txt’)
fs:remove_dir(‘/docs’)</langsyntaxhighlight>
 
=={{header|8th}}==
<syntaxhighlight lang="forth">
<lang Forth>
"input.txt" f:rm drop
"/input.txt" f:rm 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.
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program deleteFic64.s */
Line 104:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
=={{header|Action!}}==
The attached result has been obtained under DOS 2.5.
<langsyntaxhighlight Actionlang="action!">PROC Dir(CHAR ARRAY filter)
CHAR ARRAY line(255)
BYTE dev=[1]
Line 141:
PrintF("Dir ""%S""%E",filter)
Dir(filter)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Delete_a_file.png Screenshot from Atari 8-bit computer]
Line 160:
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Directories; use Ada.Directories;</langsyntaxhighlight>
and then
<langsyntaxhighlight lang="ada">Delete_File ("input.txt");
Delete_File ("/input.txt");
Delete_Tree ("docs");
Delete_Tree ("/docs");</langsyntaxhighlight>
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}}==
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.
<langsyntaxhighlight lang="aikido">
remove ("input.txt")
remove ("/input.txt")
remove ("docs")
remove ("/docs")
</syntaxhighlight>
</lang>
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">remove("input.txt");
remove("/input.txt");
remove("docs");
remove("/docs");</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="algol68">main:(
PROC remove = (STRING file name)INT:
BEGIN
Line 201:
remove("docs");
remove("/docs")
)</langsyntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program deleteFic.s */
Line 283:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">file: "input.txt"
docs: "docs"
 
Line 293:
 
delete join.path ["/" file]
delete.directory join.path ["/" docs]</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">FileDelete, input.txt
FileDelete, \input.txt
FileRemoveDir, docs, 1
FileRemoveDir, \docs, 1</langsyntaxhighlight>
===with DllCall===
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ DeleteFile @github] by jNizM
<langsyntaxhighlight AutoHotkeylang="autohotkey">DeleteFile(lpFileName)
{
DllCall("Kernel32.dll\DeleteFile", "Str", lpFileName)
}
 
DeleteFile("C:\Temp\TestFile.txt")</langsyntaxhighlight>
 
=={{header|AWK}}==
Assuming we are on a Unix/Linux or at least Cygwin system:
<langsyntaxhighlight lang="awk">system("rm input.txt")
system("rm /input.txt")
system("rm -rf docs")
system("rm -rf /docs")</langsyntaxhighlight>
 
=={{header|Axe}}==
<langsyntaxhighlight lang="axe">DelVar "appvINPUT"</langsyntaxhighlight>
 
=={{header|BASIC}}==
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.
 
<langsyntaxhighlight lang="qbasic">
KILL "INPUT.TXT"
KILL "C:\INPUT.TXT"
SHELL "RMDIR /S /Q DIR"
SHELL "RMDIR /S /Q C:\DIR"
</syntaxhighlight>
</lang>
 
==={{header|Applesoft BASIC}}===
There are disk volumes, but no folders in DOS 3.3.
<syntaxhighlight lang="gwbasic"> 0 PRINT CHR$ (4)"DELETE INPUT.TXT"</syntaxhighlight>
==={{header|BaCon}}===
BaCon has a <tt>DELETE</tt> instruction, that accepts <tt>FILE|DIRECTORY|RECURSIVE</tt> options.
 
<langsyntaxhighlight lang="freebasic">DELETE FILE "input.txt"
DELETE FILE "/input.txt"</langsyntaxhighlight>
 
Errors can be caught with the <tt>CATCH GOTO label</tt> instruction (which allows <tt>RESUME</tt> from the labelled code section).
Line 346 ⟶ 349:
file extensions. Here we delete the file named INPUTTXT from the first microdrive:
 
<langsyntaxhighlight lang="zxbasic">
ERASE "m"; 1; "INPUTTXT"
</syntaxhighlight>
</lang>
 
And for disc drive of ZX Spectrum +3:
 
<langsyntaxhighlight lang="zxbasic">
ERASE "a:INPUTTXT"
</syntaxhighlight>
</lang>
 
==={{header|BBC BASIC}}===
If the names are known as constants at compile time:
<langsyntaxhighlight lang="bbcbasic">
*DELETE input.txt
*DELETE \input.txt
*RMDIR docs
*RMDIR \docs
</syntaxhighlight>
</lang>
If the names are known only at run time:
<langsyntaxhighlight BBClang="bbc BASICbasic"> OSCLI "DELETE " + file$
OSCLI "RMDIR " + dir$</langsyntaxhighlight>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 WHEN EXCEPTION USE IOERROR
110 EXT "del input.txt"
120 EXT "del \input.txt"
Line 379 ⟶ 382:
180 PRINT "*** ";EXSTRING$(EXTYPE)
190 CONTINUE
200 END HANDLER</langsyntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">del input.txt
rd /s /q docs
 
del \input.txt
rd /s /q \docs</langsyntaxhighlight>
 
=={{header|Beef}}==
<syntaxhighlight lang="csharp">using System;
using System.IO;
 
namespace DeleteFile {
class Program {
static void Main() {
File.Delete("input.txt");
Directory.Delete("docs");
File.Delete("/input.txt");
Directory.Delete("/docs");
}
}
}</syntaxhighlight>
 
=={{header|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.RemoveDir "docs"
•file.RemoveDir "/docs"</syntaxhighlight>
 
=={{header|C}}==
ISO C:
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main() {
Line 398 ⟶ 424:
remove("/docs");
return 0;
}</langsyntaxhighlight>
 
POSIX:
<langsyntaxhighlight lang="c">#include <unistd.h>
 
int main() {
Line 409 ⟶ 435:
rmdir("/docs");
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
using System.IO;
 
Line 428 ⟶ 454:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cstdio>
#include <direct.h>
 
Line 441 ⟶ 467:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="lisp">(import '(java.io File))
(.delete (File. "output.txt"))
(.delete (File. "docs"))
 
(.delete (new File (str (File/separator) "output.txt")))
(.delete (new File (str (File/separator) "docs")))</langsyntaxhighlight>
 
=={{header|COBOL}}==
COBOL 2023 added a dedicated <code>DELETE FILE</code> statement.
To delete files or directories in COBOL we need to use unofficial extensions. The following are built-in subroutines originally created as part of some of the COBOL products created by Micro Focus.
{{works with|Visual COBOL}}
{{works with|OpenCOBOLGnuCOBOL}}
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Delete-Files.
 
PROCEDURE DIVISION.
CALL "CBL_DELETE_FILE" USING "input.txt"
CALL "CBL_DELETE_DIR" USING "docs"
CALL "CBL_DELETE_FILE" USING "/input.txt"
CALL "CBL_DELETE_DIR" USING "/docs"
 
GOBACK
.</lang>
 
Alternate method of deleting files using the <code>DELETE FILE</code> statement.
{{works with|Visual COBOL}}
<lang cobol> IDENTIFICATION DIVISION.
PROGRAM-ID. Delete-Files-2.
 
ENVIRONMENT DIVISION.
Line 482 ⟶ 494:
FD Local-File.
01 Local-Record PIC X.
 
FD Root-File.
01 Root-Record PIC X.
Line 489 ⟶ 500:
DELETE FILE Local-File
DELETE FILE Root-File
GOBACK.
 
END PROGRAM Delete-Files.</syntaxhighlight>
 
However, in some implementations we need to use unofficial extensions to delete files, or if we want to delete directories. The following are built-in subroutines originally created as part of some of the COBOL products created by Micro Focus.
{{works with|Visual COBOL}}
{{works with|GnuCOBOL}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Delete-Files.
 
PROCEDURE DIVISION.
CALL "CBL_DELETE_FILE" USING "input.txt"
CALL "CBL_DELETE_DIR" USING "docs"
CALL "CBL_DELETE_FILE" USING "/input.txt"
CALL "CBL_DELETE_DIR" USING "/docs"
 
GOBACK.
 
END PROGRAM Delete-Files.</syntaxhighlight>
GOBACK
.</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(delete-file (make-pathname :name "input.txt"))
(delete-file (make-pathname :directory '(:absolute "") :name "input.txt"))</langsyntaxhighlight>
To delete directories we need an implementation specific extension. In clisp this is ''ext:delete-dir''.
{{works with|CLISP}}
<langsyntaxhighlight lang="lisp">(let ((path (make-pathname :directory '(:relative "docs"))))
(ext:delete-dir path))
 
(let ((path (make-pathname :directory '(:absolute "docs"))))
(ext:delete-dir path))</langsyntaxhighlight>
 
Or you can use the portability library CL-FAD:
 
{{libheader|CL-FAD}}
<langsyntaxhighlight lang="lisp">(let ((path (make-pathname :directory '(:relative "docs"))))
(cl-fad:delete-directory-and-files path))</langsyntaxhighlight>
 
=={{header|Component Pascal}}==
{{Works with|BlackBox Component Builder}}
<langsyntaxhighlight lang="oberon2">
VAR
l: Files.Locator;
Line 521 ⟶ 548:
Files.dir.Delete(l,"xx.txt");
END ...
</syntaxhighlight>
</lang>
 
=={{header|D}}==
{{works with|D|2}}
<langsyntaxhighlight lang="d">import std.file: remove;
 
void main() {
remove("data.txt");
}</langsyntaxhighlight>
{{libheader|Tango}}
<langsyntaxhighlight lang="d">import tango.io.Path;
 
void main() {
Line 538 ⟶ 565:
remove("docs");
remove("/docs");
}</langsyntaxhighlight>
 
{{libheader|Tango}}
POSIX:
<langsyntaxhighlight lang="d">import tango.stdc.posix.unistd;
 
void main() {
Line 549 ⟶ 576:
rmdir("docs");
rmdir("/docs");
}</langsyntaxhighlight>
 
=={{header|Delphi}}==
<langsyntaxhighlight lang="e">procedure TMain.btnDeleteClick(Sender: TObject);
var
CurrentDirectory : String;
Line 564 ⟶ 591:
RmDir(PChar('c:\docs'));
end;
</syntaxhighlight>
</lang>
 
=={{header|E}}==
<langsyntaxhighlight lang="e"><file:input.txt>.delete(null)
<file:docs>.delete(null)
<file:///input.txt>.delete(null)
<file:///docs>.delete(null)</langsyntaxhighlight>
 
=={{header|Elena}}==
ELENA 4.x :
<langsyntaxhighlight lang="elena">import system'io;
public program()
Line 585 ⟶ 612:
Directory.assign("\docs").delete();
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">File.rm!("input.txt")
File.rmdir!("docs")
File.rm!("/input.txt")
File.rmdir!("/docs")</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(delete-file "input.txt")
<lang Lisp>
(delete-directory "docs")
;; function to remove file & directory
(delete-file "/input.txt")
(defun my-files-rm ()
(delete-filedirectory "input.txt/docs") </syntaxhighlight>
(delete-directory "docs"))
 
(my-files-rm)
(cd "~/") ;; change to home dir
(my-files-rm)
</lang>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">
-module(delete).
-export([main/0]).
Line 617 ⟶ 638:
ok = file:del_dir( "/docs" ),
ok = file:delete( "/input.txt" ).
</syntaxhighlight>
</lang>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System.IO
 
[<EntryPoint>]
Line 629 ⟶ 650:
ignore (File.Delete(Path.Combine(path, fileName)))
ignore (Directory.Delete(Path.Combine(path, dirName)))
0</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">"docs" "/docs" [ delete-tree ] bi@
"input.txt" "/input.txt" [ delete-file ] bi@</langsyntaxhighlight>
 
=={{header|Forth}}==
There is no means to delete directories in ANS Forth.
<langsyntaxhighlight lang="forth"> s" input.txt" delete-file throw
s" /input.txt" delete-file throw</langsyntaxhighlight>
 
=={{header|Fortran}}==
Line 644 ⟶ 665:
{{works with|Fortran|90 and later}}
 
<langsyntaxhighlight lang="fortran"> OPEN (UNIT=5, FILE="input.txt", STATUS="OLD") ! Current directory
CLOSE (UNIT=5, STATUS="DELETE")
OPEN (UNIT=5, FILE="/input.txt", STATUS="OLD") ! Root directory
CLOSE (UNIT=5, STATUS="DELETE")</langsyntaxhighlight>
=== 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.
 
<langsyntaxhighlight lang="fortran">program DeleteFileExample
use kernel32
implicit none
Line 659 ⟶ 680:
print *, RemoveDirectory("docs")
print *, RemoveDirectory("\docs")
end program</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="pascal">program deletion(input, output, stdErr);
const
rootDirectory = '/'; // might have to be altered for other platforms
Line 680 ⟶ 701:
rmDir(rootDirectory + docsFilename);
end.</langsyntaxhighlight>
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.
Line 688 ⟶ 709:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
' delete file and empty sub-directory in current directory
Line 703 ⟶ 724:
Print "Press any key to quit"
Sleep
</syntaxhighlight>
</lang>
 
=={{header|Furor}}==
<syntaxhighlight lang="furor">
<lang Furor>
###sysinclude dir.uh
// ===================
Line 713 ⟶ 734:
2 argv removefile
end
</syntaxhighlight>
</lang>
<pre>
Usage: furor removefile.upu filename
</pre>
 
<syntaxhighlight lang="furor">
<lang Furor>
###sysinclude dir.uh
#g argc 3 < { ."Usage: " #s 0 argv print SPACE 1 argv print SPACE ."unnecessary_directory\n" end }
Line 725 ⟶ 746:
}
end
</syntaxhighlight>
</lang>
<pre>
Usage: furor rmdir.upu unnecessary_directory
Line 731 ⟶ 752:
 
 
=={{header|Peri}}==
<syntaxhighlight lang="peri">
###sysinclude standard.uh
###sysinclude args.uh
###sysinclude str.uh
###sysinclude io.uh
// ===================
#g argc 3 < { #s ."Usage: " 0 argv print SPACE 1 argv print ." filename\n" end }
2 argv 'e inv istrue { #s ."The given file ( " 2 argv print ." ) doesn't exist!\n" end }
2 argv removefile
end
</syntaxhighlight>
<pre>
Usage: peri removefile.upu filename
</pre>
 
<syntaxhighlight lang="peri">
###sysinclude standard.uh
###sysinclude args.uh
###sysinclude str.uh
###sysinclude io.uh
#g argc 3 < { ."Usage: " #s 0 argv print SPACE 1 argv print SPACE ."unnecessary_directory\n" end }
2 argv 'd inv istrue { ."The given directory doesn't exist! Exited.\n" }{
2 argv rmdir
}
end
</syntaxhighlight>
<pre>
Usage: peri rmdir.upu unnecessary_directory
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
CFURLRef url
 
url = fn URLFileURLWithPath( fn StringByExpandingTildeInPath( @"~/Desktop/input.txt" ) )
if (fn FileManagerRemoveItemAtURL( url ) )
NSLog( @"File \"intput.txt\" deleted." )
else
NSLog( @"Unable to delete file \"input.txt\"." )
end if
 
url = fn URLFileURLWithPath( fn StringByExpandingTildeInPath( @"~/Desktop/docs" ) )
if (fn FileManagerRemoveItemAtURL( url ) )
NSLog( @"Directory \"docs\" deleted." )
else
NSLog( @"Unabled to delete directory \"docs\"." )
end if
 
HandleEvents
</syntaxhighlight>
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">Public Sub Main()
 
Kill User.home &/ "input.txt"
Line 740 ⟶ 814:
'Administrative privileges (sudo) would be required to mess about in Root - I'm not going there!
 
End</langsyntaxhighlight>
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap"># Apparently GAP can only remove a file, not a directory
RemoveFile("input.txt");
# true
RemoveFile("docs");
# fail</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
import "os"
 
Line 761 ⟶ 835:
os.RemoveAll("docs")
os.RemoveAll("/docs")
}</langsyntaxhighlight>
 
=={{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.
 
<langsyntaxhighlight lang="groovy">// Gets the first filesystem root. On most systems this will be / or c:\
def fsRoot = File.listRoots().first()
 
Line 783 ⟶ 857:
files.each{
it.directory ? it.deleteDir() : it.delete()
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
 
<langsyntaxhighlight lang="haskell">import System.IO
import System.Directory
 
Line 794 ⟶ 868:
removeDirectory "docs"
removeFile "/output.txt"
removeDirectory "/docs"</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight 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
WRITE(FIle="input.txt", DELETE=1) ! no command to DELETE a DIRECTORY in HicEst
Line 803 ⟶ 877:
SYSTEM(DIR="C:\docs") ! create C:\docs (if not existent), make it current
OPEN (FILE="input.txt", "NEW") ! in current directory = C:\docs
WRITE(FIle="input.txt", DELETE=1)</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Icon supports 'remove' for files.
<langsyntaxhighlight Uniconlang="unicon">every dir := !["./","/"] do {
remove(f := dir || "input.txt") |stop("failure for file remove ",f)
rmdir(f := dir || "docs") |stop("failure for directory remove ",f)
}
</syntaxhighlight>
</lang>
Note Icon and Unicon accept both / and \ for directory separators.
 
=={{header|Io}}==
<langsyntaxhighlight lang="io">Directory fileNamed("input.txt") remove
Directory directoryNamed("docs") remove
RootDir := Directory clone setPath("/")
RootDir fileNamed("input.txt") remove
RootDir directoryNamed("docs") remove</langsyntaxhighlight>
 
or
<langsyntaxhighlight lang="io">File with("input.txt") remove
Directory with("docs") remove
File with("/input.txt") remove
Directory with("/docs") remove</langsyntaxhighlight>
 
=={{header|J}}==
The J standard library comes with a set of file access utilities.
<langsyntaxhighlight lang="j"> load 'files'
ferase 'input.txt'
ferase '\input.txt'
Line 836 ⟶ 910:
 
NB. Or all at once...
ferase 'input.txt';'/input.txt';'docs';'/docs'</langsyntaxhighlight>
 
The function above actually uses a foreign conjunction and defined in the <tt>files</tt> library like so:
<langsyntaxhighlight lang="j">NB. =========================================================
NB.*ferase v erases a file
NB. Returns 1 if successful, otherwise _1
ferase=: (1!:55 :: _1:) @ (fboxname &>) @ boxopen</langsyntaxhighlight>
 
This means that you can directly erase files and directories without loading the <tt>files</tt> library.
<langsyntaxhighlight lang="j">1!:55 <'input.txt'
1!:55 <'\input.txt'
1!:55 <'docs'
1!:55 <'\docs'</langsyntaxhighlight>
 
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">import java.io.File;
 
public class FileDeleteTest {
Line 872 ⟶ 946:
test("directory", File.seperator + "docs" + File.seperator);
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{works with|JScript}}
<langsyntaxhighlight lang="javascript">var fso = new ActiveXObject("Scripting.FileSystemObject");
 
fso.DeleteFile('input.txt');
Line 882 ⟶ 956:
 
fso.DeleteFolder('docs');
fso.DeleteFolder('c:/docs');</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight lang="javascript">var fso = new ActiveXObject("Scripting.FileSystemObject");
var f;
f = fso.GetFile('input.txt');
Line 895 ⟶ 969:
f.Delete();
f = fso.GetFolder('c:/docs');
f.Delete();</langsyntaxhighlight>
 
{{works with|Node.js}}
Synchronous
<langsyntaxhighlight lang="javascript">const fs = require('fs');
fs.unlinkSync('myfile.txt');</langsyntaxhighlight>
Asynchronous
<langsyntaxhighlight lang="javascript">const fs = require('fs');
fs.unlink('myfile.txt', ()=>{
console.log("Done!");
})</langsyntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">"input.txt" fremove
"docs" fremove
"/input.txt" fremove
"/docs" fremove.</syntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">
# Delete a file
rm("input.txt")
Line 914 ⟶ 994:
# Delete a directory
rm("docs", recursive = true)
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
/* testing on Windows 10 which needs administrative privileges
Line 934 ⟶ 1,014:
println("$path could not be deleted")
}
}</langsyntaxhighlight>
 
{{out}}
Line 955 ⟶ 1,035:
{{libheader|LabVIEW_CWD}}
{{VI solution|LabVIEW_Delete_a_file.png}}
 
=={{header|Lang}}==
{{libheader|lang-io-module}}
<syntaxhighlight lang="lang">
# Load the IO module
# Replace "<pathToIO.lm>" with the location where the io.lm Lang module was installed to without "<" and ">"
ln.loadModule(<pathToIO.lm>)
 
$file1 = [[io]]::fp.openFile(input.txt)
[[io]]::fp.delete($file1)
[[io]]::fp.closeFile($file1)
 
$file2 = [[io]]::fp.openFile(/input.txt)
[[io]]::fp.delete($file2)
[[io]]::fp.closeFile($file2)
 
$dir1 = [[io]]::fp.openFile(docs)
[[io]]::fp.delete($dir1)
[[io]]::fp.closeFile($dir1)
 
$dir2 = [[io]]::fp.openFile(/docs)
[[io]]::fp.delete($dir2)
[[io]]::fp.closeFile($dir2)
</syntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">// delete file
local(f = file('input.txt'))
#f->delete
Line 973 ⟶ 1,077:
// directory must be empty before it can be successfully deleted. A failure is generated if the operation fails.
local(d = file('//docs'))
#d->delete</langsyntaxhighlight>
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">' show where we are
print DefaultDir$
 
Line 986 ⟶ 1,090:
kill "\input.txt"
result=rmdir("\Docs")
</syntaxhighlight>
</lang>
 
=={{header|Lingo}}==
 
Delete file "input.txt" in cwd:
<langsyntaxhighlight lang="lingo">-- note: fileIO xtra is shipped with Director, i.e. an "internal"
fp = xtra("fileIO").new()
fp.openFile("input.txt", 0)
fp.delete()</langsyntaxhighlight>
 
Delete file "input.txt" in root of current volume:
<langsyntaxhighlight lang="lingo">-- note: fileIO xtra is shipped with Director, i.e. an "internal"
pd = the last char of _movie.path -- "\" for win, ":" for mac
_player.itemDelimiter = pd
Line 1,003 ⟶ 1,107:
fp = xtra("fileIO").new()
fp.openFile(vol&pd&"input.txt", 0)
fp.delete()</langsyntaxhighlight>
 
Deleting a directory requires a 3rd party xtra, but there are various free xtras that allow this. Here as example usage of BinFile xtra:
 
<langsyntaxhighlight lang="lingo">-- delete (empty) directory "docs" in cwd
bx_folder_delete("docs")
 
Line 1,014 ⟶ 1,118:
_player.itemDelimiter = pd
vol = _movie.path.item[1]
bx_folder_delete(vol&pd&"docs")</langsyntaxhighlight>
 
=={{header|Locomotive Basic}}==
 
<langsyntaxhighlight lang="locobasic">|era,"input.txt"</langsyntaxhighlight>
([[wp:AMSDOS|AMSDOS]] RSX command, therefore prefixed with a vertical bar. Also, there are no subdirectories in AMSDOS.)
 
Line 1,024 ⟶ 1,128:
{{works with|UCB Logo}}
UCB Logo has no means to delete directories.
<langsyntaxhighlight lang="logo">erasefile "input.txt
erasefile "/input.txt</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">os.remove("input.txt")
os.remove("/input.txt")
os.remove("docs")
os.remove("/docs")</langsyntaxhighlight>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">FileTools:-Remove("input.txt");
FileTools:-RemoveDirectory("docs");
FileTools:-Remove("/input.txt");
FileTools:-RemoveDirectory("/docs");
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">wd = NotebookDirectory[];
DeleteFile[wd <> "input.txt"]
DeleteFile["/" <> "input.txt"]
DeleteDirectory[wd <> "docs"]
DeleteDirectory["/" <> "docs"]</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<langsyntaxhighlight Matlablang="matlab"> delete('input.txt'); % delete local file input.txt
delete('/input.txt'); % delete file /input.txt
rmdir('docs'); % remove local directory docs
rmdir('/docs'); % remove directory /docs
</langsyntaxhighlight>
 
On Unix-Systems:
<langsyntaxhighlight lang="matlab">if system('rm input.txt') == 0
disp('input.txt removed')
end
Line 1,067 ⟶ 1,171:
if system('rmdir /docs') == 0
disp('/docs removed')
end</langsyntaxhighlight>
 
=={{header|MAXScript}}==
There's no way to delete folders in MAXScript
<langsyntaxhighlight lang="maxscript">-- Here
deleteFile "input.txt"
-- Root
deleteFile "\input.txt"</langsyntaxhighlight>
 
=={{header|Mercury}}==
<langsyntaxhighlight lang="mercury">:- module delete_file.
:- interface.
 
Line 1,090 ⟶ 1,194:
io.remove_file("/input.txt", _, !IO),
io.remove_file("docs", _, !IO),
io.remove_file("/docs", _, !IO).</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
{{trans|Ursa}}
<langsyntaxhighlight Nanoquerylang="nanoquery">f = new(Nanoquery.IO.File)
f.delete("input.txt")
f.delete("docs")
f.delete("/input.txt")
f.delete("/docs")</langsyntaxhighlight>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.IO;
using System.Console;
Line 1,120 ⟶ 1,224:
when (Directory.Exists(@"\docs")) Directory.Delete(@"\docs");
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 1,158 ⟶ 1,262:
 
return
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(delete-file "input.txt")
(delete-file "/input.txt")
(remove-dir "docs")
(remove-dir "/docs")</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import os
removeFile("input.txt")
removeFile("/input.txt")
removeDir("docs")
removeDir("/docs")</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
use IO;
 
Line 1,188 ⟶ 1,292:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Objective-C}}==
 
<langsyntaxhighlight lang="objc">NSFileManager *fm = [NSFileManager defaultManager];
 
// Pre-OS X 10.5
Line 1,204 ⟶ 1,308:
[fm removeItemAtPath:@"/input.txt" error:NULL];
[fm removeItemAtPath:@"docs" error:NULL];
[fm removeItemAtPath:@"/docs" error:NULL];</langsyntaxhighlight>
 
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml">Sys.remove "input.txt";;
Sys.remove "/input.txt";;</lang>
Sys.rmdir "docs";;
Sys.rmdir "/docs";;</syntaxhighlight>
 
with the Unix library:
<langsyntaxhighlight lang="ocaml">#load "unix.cma";;
Unix.unlink "input.txt";;
Unix.unlink "/input.txt";;
Unix.rmdir "docs";;
Unix.rmdir "/docs";;</langsyntaxhighlight>
 
=={{header|ooRexx}}==
<langsyntaxhighlight lang="oorexx">/*REXX pgm deletes a file */
file= 'afile.txt' /*name of a file to be deleted.*/
res=sysFileDelete(file); Say file 'res='res
File= 'bfile.txt' /*name of a file to be deleted.*/
res=sysFileDelete(file); Say file 'res='res</langsyntaxhighlight>
{{out}}
<pre>afile.txt res=0
Line 1,229 ⟶ 1,335:
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">for Dir in ["/" "./"] do
try {OS.unlink Dir#"output.txt"}
catch _ then {System.showInfo "File does not exist."} end
try {OS.rmDir Dir#"docs"}
catch _ then {System.showInfo "Directory does not exist."} end
end</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
GP has no built-in facilities for deleting files, but can use a system call:
<langsyntaxhighlight lang="parigp">system("rm -rf docs");
system("rm input.txt");
system("rm -rf /docs");
system("rm /input.txt");</langsyntaxhighlight>
PARI, as usual, has access to all the standard [[#C|C]] methods.
 
Line 1,249 ⟶ 1,355:
=={{header|Perl}}==
 
<langsyntaxhighlight lang="perl">use File::Spec::Functions qw(catfile rootdir);
# here
unlink 'input.txt';
Line 1,255 ⟶ 1,361:
# root dir
unlink catfile rootdir, 'input.txt';
rmdir catfile rootdir, 'docs';</langsyntaxhighlight>
 
'''Without Perl Modules'''
Line 1,268 ⟶ 1,374:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<lang Phix>constant root = iff(platform()=LINUX?"/":"C:\\")
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
?delete_file("input.txt")
<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>
?delete_file(root&"input.txt")
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">delete_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"input.txt"</span><span style="color: #0000FF;">)</span>
?remove_directory("docs")
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">delete_file</span><span style="color: #0000FF;">(</span><span style="color: #000000;">root</span><span style="color: #0000FF;">&</span><span style="color: #008000;">"input.txt"</span><span style="color: #0000FF;">)</span>
?remove_directory(root&"docs")</lang>
<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>
<!--</syntaxhighlight>-->
output is 0 0 0 0 or 1 1 1 1 or some combination thereof
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
unlink('input.txt');
unlink('/input.txt');
rmdir('docs');
rmdir('/docs');
?></langsyntaxhighlight>
 
=={{header|Picat}}==
{{works with|Picat}}
<syntaxhighlight lang="picat">
import os.
 
del(Arg), directory(Arg) =>
rmdir(Arg).
 
del(Arg), file(Arg) =>
rm(Arg).
 
main(Args) =>
foreach (Arg in Args)
del(Arg)
end.
</syntaxhighlight>
{{out}}
<pre>
picat delete_file.pi input.txt docs/ /input.txt /docs/
</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(call 'rm "input.txt")
(call 'rmdir "docs")
(call 'rm "/input.txt")
(call 'rmdir "/docs")</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">int main(){
rm("input.txt");
rm("/input.txt");
rm("docs");
rm("/docs");
}</langsyntaxhighlight>
 
=={{header|Plain English}}==
<syntaxhighlight lang="text">
To run:
Start up.
\ In the current working directory
Destroy ".\input.txt" in the file system.
Destroy ".\docs\" in the file system.
\ In the filesystem root
Destroy "C:\input.txt" in the file system.
Destroy "C:\docs\" in the file system.
Shut down.
</syntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell"># possible aliases for Remove-Item: rm, del, ri
Remove-Item input.txt
Remove-Item \input.txt # file system root
 
Remove-Item -Recurse docs # recurse for deleting folders including content
Remove-Item -Recurse \docs</langsyntaxhighlight>
 
=={{header|ProDOS}}==
Because input.txt is located inside of "docs" this will delete it when it deletes "docs"
<syntaxhighlight lang ProDOS="prodos">deletedirectory docs</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">DeleteFile("input.txt")
DeleteDirectory("docs","") ; needs to delete all included files
DeleteFile("/input.txt")
DeleteDirectory("/docs","*.*") ; deletes all files according to a pattern
 
DeleteDirectory("/docs","",#PB_FileSystem_Recursive) ; deletes all files and directories recursive</langsyntaxhighlight>
 
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">import os
# current directory
os.remove("output.txt")
Line 1,325 ⟶ 1,468:
# root directory
os.remove("/output.txt")
os.rmdir("/docs")</langsyntaxhighlight>
If you wanted to remove a directory and all its contents, recursively, you would do:
<langsyntaxhighlight lang="python">import shutil
shutil.rmtree("docs")</langsyntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">file.remove("input.txt")
file.remove("/input.txt")
 
Line 1,342 ⟶ 1,485:
# directories needs the recursive flag
unlink("docs", recursive = TRUE)
unlink("/docs", recursive = TRUE)</langsyntaxhighlight>
 
The function <tt>unlink</tt> allows wildcards (* and ?)
Line 1,348 ⟶ 1,491:
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
 
Line 1,366 ⟶ 1,509:
(delete-directory "docs")
(delete-directory/files "docs"))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>unlink 'input.txt';
unlink '/input.txt';
rmdir 'docs';
rmdir '/docs';</langsyntaxhighlight>
 
=={{header|Raven}}==
 
<langsyntaxhighlight lang="raven">'input.txt' delete
'/input.txt' delete
'docs' rmdir
'/docs' rmdir</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">; Local.
delete %input.txt
delete-dir %docs/
Line 1,389 ⟶ 1,532:
; Root.
delete %/input.txt
delete-dir %/docs/</langsyntaxhighlight>
 
=={{header|Retro}}==
<langsyntaxhighlight Retrolang="retro">'input.txt file:delete
'/input.txt file:delete</langsyntaxhighlight>
 
=={{header|REXX}}==
Note that this REXX program will work on the Next family of Microsoft Windows systems as well as DOS &nbsp; (both under Windows in a DOS-prompt window or stand-alone DOS).
<langsyntaxhighlight 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*/
aFile= 'input.txt' /*name of a file to be deleted. */
Line 1,406 ⟶ 1,549:
if j==1 then 'CD \' /*make the current dir the root dir.*/
end /* [↑] just do CD \ command once.*/
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
 
=={{header|Ring}}==
 
<langsyntaxhighlight lang="ring">
remove("output.txt")
system("rmdir docs")
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
There is a unique RPL instruction to delete both files and directories. Directories must be empty to be deletable.
'output.txt' PURGE
'docs' PURGE
HOME output.txt' PURGE
HOME 'docs' PURGE
Basically, <code>HOME</code> moves the user from the current directory to the root. If the last two commands are done successively, only the first call is necessary.
 
=={{header|Ruby}}==
 
<langsyntaxhighlight lang="ruby">File.delete("output.txt", "/output.txt")
Dir.delete("docs")
Dir.delete("/docs")</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">'------ delete input.txt ----------------
kill "input.txt" ' this is where we are
kill "/input.txt" ' this is the root
Line 1,428 ⟶ 1,579:
' ---- delete directory docs ----------
result = rmdir("Docs") ' directory where we are
result = rmdir("/Docs") ' root directory</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">use std::io::{self, Write};
use std::fs::{remove_file,remove_dir};
use std::path::Path;
Line 1,455 ⟶ 1,606:
let _ = writeln!(&mut io::stderr(), "{:?}", error);
process::exit(code)
}</langsyntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
<langsyntaxhighlight lang="scala">import java.util._
import java.io.File
 
Line 1,473 ⟶ 1,624:
test("directory", "docs")
test("directory", File.separatorChar + "docs" + File.separatorChar)
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
{{works with|Scheme|R6RS}}[http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-10.html]
<syntaxhighlight lang ="scheme">(delete-file filename)</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "osfiles.s7i";
 
Line 1,490 ⟶ 1,641:
removeTree("docs");
removeTree("/docs");
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">// Delete locally (relative to "the folder")
delete file "input.txt"
delete folder "docs"
Line 1,500 ⟶ 1,651:
delete file "/input.txt"
delete folder "/docs"
</syntaxhighlight>
</lang>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby"># here
%f'input.txt' -> delete;
%d'docs' -> delete;
Line 1,509 ⟶ 1,660:
# root dir
Dir.root + %f'input.txt' -> delete;
Dir.root + %d'docs' -> delete;</langsyntaxhighlight>
 
=={{header|Slate}}==
Line 1,515 ⟶ 1,666:
(It will succeed deleting the directory if it is empty)
 
<langsyntaxhighlight lang="slate">(File newNamed: 'input.txt') delete.
(File newNamed: '/input.txt') delete.
(Directory newNamed: 'docs') delete.
(Directory newNamed: '/docs') delete.</langsyntaxhighlight>
 
Also:
 
<langsyntaxhighlight lang="slate">
(Directory current / 'input.txt') delete.
(Directory root / 'input.txt') delete.</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
Line 1,530 ⟶ 1,681:
(It will succeed deleting the directory if it is empty)
 
<langsyntaxhighlight lang="smalltalk">File remove: 'input.txt'.
File remove: 'docs'.
File remove: '/input.txt'.
File remove: '/docs'</langsyntaxhighlight>
 
=={{header|Standard ML}}==
 
<langsyntaxhighlight lang="sml">OS.FileSys.remove "input.txt";
OS.FileSys.remove "/input.txt";
OS.FileSys.rmDir "docs";
OS.FileSys.rmDir "/docs";</langsyntaxhighlight>
 
=={{header|Stata}}==
<langsyntaxhighlight lang="stata">erase input.txt
rmdir docs</langsyntaxhighlight>
 
=={{header|Tcl}}==
 
<langsyntaxhighlight lang="tcl">file delete input.txt /input.txt
 
# preserve directory if non-empty
Line 1,554 ⟶ 1,705:
 
# delete even if non-empty
file delete -force docs /docs</langsyntaxhighlight>
 
=={{header|Toka}}==
 
<langsyntaxhighlight lang="toka">needs shell
" docs" remove
" input.txt" remove</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
- delete file
Line 1,569 ⟶ 1,720:
- delete directory
SET status = DELETE ("docs",-std-)
</syntaxhighlight>
</lang>
 
=={{header|UNIX Shell}}==
<langsyntaxhighlight lang="bash">rm -rf docs
rm input.txt
rm -rf /docs
rm /input.txt</langsyntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">decl file f
f.delete "input.txt"
f.delete "docs"
f.delete "/input.txt"
f.delete "/docs"</langsyntaxhighlight>
 
=={{header|VAX Assembly}}==
<langsyntaxhighlight VAXlang="vax Assemblyassembly">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
3B 72 69 0018
Line 1,604 ⟶ 1,755:
0071 12 .end main
 
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Option Explicit
 
Sub DeleteFileOrDirectory()
Line 1,616 ⟶ 1,767:
'delete Directory
RmDir myPath
End Sub</langsyntaxhighlight>
 
=={{header|VBScript}}==
<langsyntaxhighlight lang="vb">Set oFSO = CreateObject( "Scripting.FileSystemObject" )
 
oFSO.DeleteFile "input.txt"
Line 1,641 ⟶ 1,792:
fld.Delete
 
</syntaxhighlight>
</lang>
 
=={{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.
<langsyntaxhighlight lang="vedit">// In current directory
File_Delete("input.txt", OK)
File_Rmdir("docs")
Line 1,651 ⟶ 1,802:
// In the root directory
File_Delete("/input.txt", OK)
File_Rmdir("/docs")</langsyntaxhighlight>
 
=={{header|Visual Basic .NET}}==
Line 1,657 ⟶ 1,808:
 
{{works with|Visual Basic .NET|9.0+}}
<langsyntaxhighlight lang="vbnet">'Current Directory
IO.Directory.Delete("docs")
IO.Directory.Delete("docs", True) 'also delete files and sub-directories
Line 1,668 ⟶ 1,819:
'Root, platform independent
IO.Directory.Delete(IO.Path.DirectorySeparatorChar & "docs")
IO.File.Delete(IO.Path.DirectorySeparatorChar & "output.txt")</langsyntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Rust">
import os
 
fn main() {
os.rm("./input.txt") or {println(err) exit(-1)}
os.rmdir("./docs") or {println(err) exit(-2)} // os.rmdir_all, recursively removes specified directory
// check if file exists
if os.is_file("./input.txt") == true {println("Found file!")}
else {println("File was not found!")}
// check if directory exists
if os.is_dir("./docs") == true {println("Found directory!")}
else {println("Directory was not found!")}
}
</syntaxhighlight>
 
=={{header|Wren}}==
Line 1,674 ⟶ 1,841:
 
Wren does not currently support the removal of directories.
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
 
File.delete("input.txt")
 
// check it worked
System.print(File.exists("input.txt"))</langsyntaxhighlight>
 
{{out}}
Line 1,689 ⟶ 1,856:
{{works with|NASM|Linux}}
 
<langsyntaxhighlight lang="asm">
;syscall numbers for readability. :]
%define sys_rmdir 40
Line 1,735 ⟶ 1,902:
err_msg db "Something went wrong! :[",0xa
err_len equ $-err_msg
</syntaxhighlight>
</lang>
 
=={{header|Yorick}}==
Yorick does not have a built-in function to recursively delete a directory; the rmdir function only works on empty directories.
<langsyntaxhighlight lang="yorick">remove, "input.txt";
remove, "/input.txt";
rmdir, "docs";
rmdir, "/docs";</langsyntaxhighlight>
 
=={{header|zig}}==
 
<syntaxhighlight lang="zig">const std = @import("std");
const fs = std.fs;
 
pub fn main() !void {
const here = fs.cwd();
try here.deleteFile("input.txt");
try here.deleteDir("docs");
 
const root = try fs.openDirAbsolute("/", .{});
try root.deleteFile("input.txt");
try root.deleteDir("docs");
}</syntaxhighlight>
 
=={{header|zkl}}==
zkl doesn't have built ins to delete files or directories but you can let a shell do it:
<langsyntaxhighlight lang="zkl">zkl: System.cmd((System.isWindows and "del" or "unlink") + " input.txt")
0
zkl: System.cmd((System.isWindows and "del" or "unlink") + " /input.txt")
Line 1,758 ⟶ 1,940:
zkl: System.cmd("rm -r /docs")
rm: cannot remove ‘/docs’: No such file or directory
256</langsyntaxhighlight>
 
{{omit from|Befunge}} <!-- No filesystem support -->
{{omit from|EasyLang}}
{{omit from|HTML}}
{{omit from|Openscad}}
9,476

edits