Delete a file: Difference between revisions
m
syntax highlighting fixup automation
(add BQN) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8:
=={{header|11l}}==
<
fs:remove_dir(‘docs’)
fs:remove_file(‘/output.txt’)
fs:remove_dir(‘/docs’)</
=={{header|8th}}==
<syntaxhighlight lang="forth">
"input.txt" f:rm drop
"/input.txt" f:rm drop
"docs" f:rmdir drop
"/docs" f:rmdir drop
</syntaxhighlight>
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">
/* 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>
=={{header|Action!}}==
The attached result has been obtained under DOS 2.5.
<
CHAR ARRAY line(255)
BYTE dev=[1]
Line 141:
PrintF("Dir ""%S""%E",filter)
Dir(filter)
RETURN</
{{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}}==
<
and then
<
Delete_File ("/input.txt");
Delete_Tree ("docs");
Delete_Tree ("/docs");</
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.
<
remove ("input.txt")
remove ("/input.txt")
remove ("docs")
remove ("/docs")
</syntaxhighlight>
=={{header|Aime}}==
<
remove("/input.txt");
remove("docs");
remove("/docs");</
=={{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.
<
PROC remove = (STRING file name)INT:
BEGIN
Line 201:
remove("docs");
remove("/docs")
)</
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program deleteFic.s */
Line 283:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
=={{header|Arturo}}==
<
docs: "docs"
Line 293:
delete join.path ["/" file]
delete.directory join.path ["/" docs]</
=={{header|AutoHotkey}}==
<
FileDelete, \input.txt
FileRemoveDir, docs, 1
FileRemoveDir, \docs, 1</
===with DllCall===
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ DeleteFile @github] by jNizM
<
{
DllCall("Kernel32.dll\DeleteFile", "Str", lpFileName)
}
DeleteFile("C:\Temp\TestFile.txt")</
=={{header|AWK}}==
Assuming we are on a Unix/Linux or at least Cygwin system:
<
system("rm /input.txt")
system("rm -rf docs")
system("rm -rf /docs")</
=={{header|Axe}}==
<
=={{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.
<
KILL "INPUT.TXT"
KILL "C:\INPUT.TXT"
SHELL "RMDIR /S /Q DIR"
SHELL "RMDIR /S /Q C:\DIR"
</syntaxhighlight>
==={{header|Applesoft BASIC}}===
There are disk volumes, but no folders in DOS 3.3.
<
==={{header|BaCon}}===
BaCon has a <tt>DELETE</tt> instruction, that accepts <tt>FILE|DIRECTORY|RECURSIVE</tt> options.
<
DELETE FILE "/input.txt"</
Errors can be caught with the <tt>CATCH GOTO label</tt> instruction (which allows <tt>RESUME</tt> from the labelled code section).
Line 349:
file extensions. Here we delete the file named INPUTTXT from the first microdrive:
<
ERASE "m"; 1; "INPUTTXT"
</syntaxhighlight>
And for disc drive of ZX Spectrum +3:
<
ERASE "a:INPUTTXT"
</syntaxhighlight>
==={{header|BBC BASIC}}===
If the names are known as constants at compile time:
<
*DELETE input.txt
*DELETE \input.txt
*RMDIR docs
*RMDIR \docs
</syntaxhighlight>
If the names are known only at run time:
<
OSCLI "RMDIR " + dir$</
==={{header|IS-BASIC}}===
<
110 EXT "del input.txt"
120 EXT "del \input.txt"
Line 382:
180 PRINT "*** ";EXSTRING$(EXTYPE)
190 CONTINUE
200 END HANDLER</
=={{header|Batch File}}==
<
rd /s /q docs
del \input.txt
rd /s /q \docs</
=={{header|BQN}}==
File operations are under the system value <code>•file</code> in BQN.
<
•file.Remove "/input.txt"
•file.RemoveDir "docs"
•file.RemoveDir "/docs"</
=={{header|C}}==
ISO C:
<
int main() {
Line 409:
remove("/docs");
return 0;
}</
POSIX:
<
int main() {
Line 420:
rmdir("/docs");
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.IO;
Line 439:
}
}
}</
=={{header|C++}}==
<
#include <direct.h>
Line 452:
return 0;
}</
=={{header|Clojure}}==
<
(.delete (File. "output.txt"))
(.delete (File. "docs"))
(.delete (new File (str (File/separator) "output.txt")))
(.delete (new File (str (File/separator) "docs")))</
=={{header|COBOL}}==
Line 466:
{{works with|Visual COBOL}}
{{works with|OpenCOBOL}}
<
PROGRAM-ID. Delete-Files.
Line 476:
GOBACK
.</
Alternate method of deleting files using the <code>DELETE FILE</code> statement.
{{works with|Visual COBOL}}
<
PROGRAM-ID. Delete-Files-2.
Line 502:
GOBACK
.</
=={{header|Common Lisp}}==
<
(delete-file (make-pathname :directory '(:absolute "") :name "input.txt"))</
To delete directories we need an implementation specific extension. In clisp this is ''ext:delete-dir''.
{{works with|CLISP}}
<
(ext:delete-dir path))
(let ((path (make-pathname :directory '(:absolute "docs"))))
(ext:delete-dir path))</
Or you can use the portability library CL-FAD:
{{libheader|CL-FAD}}
<
(cl-fad:delete-directory-and-files path))</
=={{header|Component Pascal}}==
{{Works with|BlackBox Component Builder}}
<
VAR
l: Files.Locator;
Line 532:
Files.dir.Delete(l,"xx.txt");
END ...
</syntaxhighlight>
=={{header|D}}==
{{works with|D|2}}
<
void main() {
remove("data.txt");
}</
{{libheader|Tango}}
<
void main() {
Line 549:
remove("docs");
remove("/docs");
}</
{{libheader|Tango}}
POSIX:
<
void main() {
Line 560:
rmdir("docs");
rmdir("/docs");
}</
=={{header|Delphi}}==
<
var
CurrentDirectory : String;
Line 575:
RmDir(PChar('c:\docs'));
end;
</syntaxhighlight>
=={{header|E}}==
<
<file:docs>.delete(null)
<file:///input.txt>.delete(null)
<file:///docs>.delete(null)</
=={{header|Elena}}==
ELENA 4.x :
<
public program()
Line 596:
Directory.assign("\docs").delete();
}</
=={{header|Elixir}}==
<
File.rmdir!("docs")
File.rm!("/input.txt")
File.rmdir!("/docs")</
=={{header|Emacs Lisp}}==
<
(delete-directory "docs")
(delete-file "/input.txt")
(delete-directory "/docs")</
=={{header|Erlang}}==
<
-module(delete).
-export([main/0]).
Line 622:
ok = file:del_dir( "/docs" ),
ok = file:delete( "/input.txt" ).
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
<
[<EntryPoint>]
Line 634:
ignore (File.Delete(Path.Combine(path, fileName)))
ignore (Directory.Delete(Path.Combine(path, dirName)))
0</
=={{header|Factor}}==
<
"input.txt" "/input.txt" [ delete-file ] bi@</
=={{header|Forth}}==
There is no means to delete directories in ANS Forth.
<
s" /input.txt" delete-file throw</
=={{header|Fortran}}==
Line 649:
{{works with|Fortran|90 and later}}
<
CLOSE (UNIT=5, STATUS="DELETE")
OPEN (UNIT=5, FILE="/input.txt", STATUS="OLD") ! Root directory
CLOSE (UNIT=5, STATUS="DELETE")</
=== 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 kernel32
implicit none
Line 664:
print *, RemoveDirectory("docs")
print *, RemoveDirectory("\docs")
end program</
=={{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.
<
const
rootDirectory = '/'; // might have to be altered for other platforms
Line 685:
rmDir(rootDirectory + docsFilename);
end.</
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 693:
=={{header|FreeBASIC}}==
<
' delete file and empty sub-directory in current directory
Line 708:
Print "Press any key to quit"
Sleep
</syntaxhighlight>
=={{header|Furor}}==
<syntaxhighlight lang="furor">
###sysinclude dir.uh
// ===================
Line 718:
2 argv removefile
end
</syntaxhighlight>
<pre>
Usage: furor removefile.upu filename
</pre>
<syntaxhighlight lang="furor">
###sysinclude dir.uh
#g argc 3 < { ."Usage: " #s 0 argv print SPACE 1 argv print SPACE ."unnecessary_directory\n" end }
Line 730:
}
end
</syntaxhighlight>
<pre>
Usage: furor rmdir.upu unnecessary_directory
Line 738:
=={{header|Gambas}}==
<
Kill User.home &/ "input.txt"
Line 745:
'Administrative privileges (sudo) would be required to mess about in Root - I'm not going there!
End</
=={{header|GAP}}==
<
RemoveFile("input.txt");
# true
RemoveFile("docs");
# fail</
=={{header|Go}}==
<
import "os"
Line 766:
os.RemoveAll("docs")
os.RemoveAll("/docs")
}</
=={{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.
<
def fsRoot = File.listRoots().first()
Line 788:
files.each{
it.directory ? it.deleteDir() : it.delete()
}</
=={{header|Haskell}}==
<
import System.Directory
Line 799:
removeDirectory "docs"
removeFile "/output.txt"
removeDirectory "/docs"</
=={{header|HicEst}}==
<
OPEN (FILE="input.txt", "NEW") ! in current directory = docs
WRITE(FIle="input.txt", DELETE=1) ! no command to DELETE a DIRECTORY in HicEst
Line 808:
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)</
=={{header|Icon}} and {{header|Unicon}}==
Icon supports 'remove' for files.
<
remove(f := dir || "input.txt") |stop("failure for file remove ",f)
rmdir(f := dir || "docs") |stop("failure for directory remove ",f)
}
</syntaxhighlight>
Note Icon and Unicon accept both / and \ for directory separators.
=={{header|Io}}==
<
Directory directoryNamed("docs") remove
RootDir := Directory clone setPath("/")
RootDir fileNamed("input.txt") remove
RootDir directoryNamed("docs") remove</
or
<
Directory with("docs") remove
File with("/input.txt") remove
Directory with("/docs") remove</
=={{header|J}}==
The J standard library comes with a set of file access utilities.
<
ferase 'input.txt'
ferase '\input.txt'
Line 841:
NB. Or all at once...
ferase 'input.txt';'/input.txt';'docs';'/docs'</
The function above actually uses a foreign conjunction and defined in the <tt>files</tt> library like so:
<
NB.*ferase v erases a file
NB. Returns 1 if successful, otherwise _1
ferase=: (1!:55 :: _1:) @ (fboxname &>) @ boxopen</
This means that you can directly erase files and directories without loading the <tt>files</tt> library.
<
1!:55 <'\input.txt'
1!:55 <'docs'
1!:55 <'\docs'</
=={{header|Java}}==
<
public class FileDeleteTest {
Line 877:
test("directory", File.seperator + "docs" + File.seperator);
}
}</
=={{header|JavaScript}}==
{{works with|JScript}}
<
fso.DeleteFile('input.txt');
Line 887:
fso.DeleteFolder('docs');
fso.DeleteFolder('c:/docs');</
or
<
var f;
f = fso.GetFile('input.txt');
Line 900:
f.Delete();
f = fso.GetFolder('c:/docs');
f.Delete();</
{{works with|Node.js}}
Synchronous
<
fs.unlinkSync('myfile.txt');</
Asynchronous
<
fs.unlink('myfile.txt', ()=>{
console.log("Done!");
})</
=={{header|Julia}}==
<
# Delete a file
rm("input.txt")
Line 919:
# Delete a directory
rm("docs", recursive = true)
</syntaxhighlight>
=={{header|Kotlin}}==
<
/* testing on Windows 10 which needs administrative privileges
Line 939:
println("$path could not be deleted")
}
}</
{{out}}
Line 962:
=={{header|Lasso}}==
<
local(f = file('input.txt'))
#f->delete
Line 978:
// directory must be empty before it can be successfully deleted. A failure is generated if the operation fails.
local(d = file('//docs'))
#d->delete</
=={{header|Liberty BASIC}}==
<
print DefaultDir$
Line 991:
kill "\input.txt"
result=rmdir("\Docs")
</syntaxhighlight>
=={{header|Lingo}}==
Delete file "input.txt" in cwd:
<
fp = xtra("fileIO").new()
fp.openFile("input.txt", 0)
fp.delete()</
Delete file "input.txt" in root of current volume:
<
pd = the last char of _movie.path -- "\" for win, ":" for mac
_player.itemDelimiter = pd
Line 1,008:
fp = xtra("fileIO").new()
fp.openFile(vol&pd&"input.txt", 0)
fp.delete()</
Deleting a directory requires a 3rd party xtra, but there are various free xtras that allow this. Here as example usage of BinFile xtra:
<
bx_folder_delete("docs")
Line 1,019:
_player.itemDelimiter = pd
vol = _movie.path.item[1]
bx_folder_delete(vol&pd&"docs")</
=={{header|Locomotive Basic}}==
<
([[wp:AMSDOS|AMSDOS]] RSX command, therefore prefixed with a vertical bar. Also, there are no subdirectories in AMSDOS.)
Line 1,029:
{{works with|UCB Logo}}
UCB Logo has no means to delete directories.
<
erasefile "/input.txt</
=={{header|Lua}}==
<
os.remove("/input.txt")
os.remove("docs")
os.remove("/docs")</
=={{header|Maple}}==
<
FileTools:-RemoveDirectory("docs");
FileTools:-Remove("/input.txt");
FileTools:-RemoveDirectory("/docs");
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
DeleteFile[wd <> "input.txt"]
DeleteFile["/" <> "input.txt"]
DeleteDirectory[wd <> "docs"]
DeleteDirectory["/" <> "docs"]</
=={{header|MATLAB}} / {{header|Octave}}==
<
delete('/input.txt'); % delete file /input.txt
rmdir('docs'); % remove local directory docs
rmdir('/docs'); % remove directory /docs
</
On Unix-Systems:
<
disp('input.txt removed')
end
Line 1,072:
if system('rmdir /docs') == 0
disp('/docs removed')
end</
=={{header|MAXScript}}==
There's no way to delete folders in MAXScript
<
deleteFile "input.txt"
-- Root
deleteFile "\input.txt"</
=={{header|Mercury}}==
<
:- interface.
Line 1,095:
io.remove_file("/input.txt", _, !IO),
io.remove_file("docs", _, !IO),
io.remove_file("/docs", _, !IO).</
=={{header|Nanoquery}}==
{{trans|Ursa}}
<
f.delete("input.txt")
f.delete("docs")
f.delete("/input.txt")
f.delete("/docs")</
=={{header|Nemerle}}==
<
using System.IO;
using System.Console;
Line 1,125:
when (Directory.Exists(@"\docs")) Directory.Delete(@"\docs");
}
}</
=={{header|NetRexx}}==
<
options replace format comments java crossref symbols binary
Line 1,163:
return
</syntaxhighlight>
=={{header|NewLISP}}==
<
(delete-file "/input.txt")
(remove-dir "docs")
(remove-dir "/docs")</
=={{header|Nim}}==
<
removeFile("input.txt")
removeFile("/input.txt")
removeDir("docs")
removeDir("/docs")</
=={{header|Objeck}}==
<
use IO;
Line 1,193:
}
}
</syntaxhighlight>
=={{header|Objective-C}}==
<
// Pre-OS X 10.5
Line 1,209:
[fm removeItemAtPath:@"/input.txt" error:NULL];
[fm removeItemAtPath:@"docs" error:NULL];
[fm removeItemAtPath:@"/docs" error:NULL];</
=={{header|OCaml}}==
<
Sys.remove "/input.txt";;</
with the Unix library:
<
Unix.unlink "input.txt";;
Unix.unlink "/input.txt";;
Unix.rmdir "docs";;
Unix.rmdir "/docs";;</
=={{header|ooRexx}}==
<
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</
{{out}}
<pre>afile.txt res=0
Line 1,234:
=={{header|Oz}}==
<
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</
=={{header|PARI/GP}}==
GP has no built-in facilities for deleting files, but can use a system call:
<
system("rm input.txt");
system("rm -rf /docs");
system("rm /input.txt");</
PARI, as usual, has access to all the standard [[#C|C]] methods.
Line 1,254:
=={{header|Perl}}==
<
# here
unlink 'input.txt';
Line 1,260:
# root dir
unlink catfile rootdir, 'input.txt';
rmdir catfile rootdir, 'docs';</
'''Without Perl Modules'''
Line 1,273:
=={{header|Phix}}==
<!--<
<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>
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: #000000;">root</span><span style="color: #0000FF;">&</span><span style="color: #008000;">"docs"</span><span style="color: #0000FF;">)</span>
<!--</
output is 0 0 0 0 or 1 1 1 1 or some combination thereof
=={{header|PHP}}==
<
unlink('input.txt');
unlink('/input.txt');
rmdir('docs');
rmdir('/docs');
?></
=={{header|Picat}}==
{{works with|Picat}}
<syntaxhighlight lang="picat">
import os.
Line 1,306:
del(Arg)
end.
</syntaxhighlight>
{{out}}
<pre>
Line 1,313:
=={{header|PicoLisp}}==
<
(call 'rmdir "docs")
(call 'rm "/input.txt")
(call 'rmdir "/docs")</
=={{header|Pike}}==
<
rm("input.txt");
rm("/input.txt");
rm("docs");
rm("/docs");
}</
=={{header|PowerShell}}==
<
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</
=={{header|ProDOS}}==
Because input.txt is located inside of "docs" this will delete it when it deletes "docs"
<syntaxhighlight lang
=={{header|PureBasic}}==
<
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</
=={{header|Python}}==
<
# current directory
os.remove("output.txt")
Line 1,354:
# root directory
os.remove("/output.txt")
os.rmdir("/docs")</
If you wanted to remove a directory and all its contents, recursively, you would do:
<
shutil.rmtree("docs")</
=={{header|R}}==
<
file.remove("/input.txt")
Line 1,371:
# directories needs the recursive flag
unlink("docs", recursive = TRUE)
unlink("/docs", recursive = TRUE)</
The function <tt>unlink</tt> allows wildcards (* and ?)
Line 1,377:
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
Line 1,395:
(delete-directory "docs")
(delete-directory/files "docs"))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
unlink '/input.txt';
rmdir 'docs';
rmdir '/docs';</
=={{header|Raven}}==
<
'/input.txt' delete
'docs' rmdir
'/docs' rmdir</
=={{header|REBOL}}==
<
delete %input.txt
delete-dir %docs/
Line 1,418:
; Root.
delete %/input.txt
delete-dir %/docs/</
=={{header|Retro}}==
<
'/input.txt file:delete</
=={{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).
<
trace off /*suppress REXX error messages from DOS*/
aFile= 'input.txt' /*name of a file to be deleted. */
Line 1,435:
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. */</
=={{header|Ring}}==
<
remove("output.txt")
system("rmdir docs")
</syntaxhighlight>
=={{header|Ruby}}==
<
Dir.delete("docs")
Dir.delete("/docs")</
=={{header|Run BASIC}}==
<
kill "input.txt" ' this is where we are
kill "/input.txt" ' this is the root
Line 1,457:
' ---- delete directory docs ----------
result = rmdir("Docs") ' directory where we are
result = rmdir("/Docs") ' root directory</
=={{header|Rust}}==
<
use std::fs::{remove_file,remove_dir};
use std::path::Path;
Line 1,484:
let _ = writeln!(&mut io::stderr(), "{:?}", error);
process::exit(code)
}</
=={{header|Scala}}==
{{libheader|Scala}}
<
import java.io.File
Line 1,502:
test("directory", "docs")
test("directory", File.separatorChar + "docs" + File.separatorChar)
}</
=={{header|Scheme}}==
{{works with|Scheme|R6RS}}[http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-10.html]
<syntaxhighlight lang
=={{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.
<
include "osfiles.s7i";
Line 1,519:
removeTree("docs");
removeTree("/docs");
end func;</
=={{header|SenseTalk}}==
<
delete file "input.txt"
delete folder "docs"
Line 1,529:
delete file "/input.txt"
delete folder "/docs"
</syntaxhighlight>
=={{header|Sidef}}==
<
%f'input.txt' -> delete;
%d'docs' -> delete;
Line 1,538:
# root dir
Dir.root + %f'input.txt' -> delete;
Dir.root + %d'docs' -> delete;</
=={{header|Slate}}==
Line 1,544:
(It will succeed deleting the directory if it is empty)
<
(File newNamed: '/input.txt') delete.
(Directory newNamed: 'docs') delete.
(Directory newNamed: '/docs') delete.</
Also:
<
(Directory current / 'input.txt') delete.
(Directory root / 'input.txt') delete.</
=={{header|Smalltalk}}==
Line 1,559:
(It will succeed deleting the directory if it is empty)
<
File remove: 'docs'.
File remove: '/input.txt'.
File remove: '/docs'</
=={{header|Standard ML}}==
<
OS.FileSys.remove "/input.txt";
OS.FileSys.rmDir "docs";
OS.FileSys.rmDir "/docs";</
=={{header|Stata}}==
<
rmdir docs</
=={{header|Tcl}}==
<
# preserve directory if non-empty
Line 1,583:
# delete even if non-empty
file delete -force docs /docs</
=={{header|Toka}}==
<
" docs" remove
" input.txt" remove</
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
- delete file
Line 1,598:
- delete directory
SET status = DELETE ("docs",-std-)
</syntaxhighlight>
=={{header|UNIX Shell}}==
<
rm input.txt
rm -rf /docs
rm /input.txt</
=={{header|Ursa}}==
<
f.delete "input.txt"
f.delete "docs"
f.delete "/input.txt"
f.delete "/docs"</
=={{header|VAX Assembly}}==
<
64 2E 73 63 6F 64 2C 3B 74 78 74 2E 000C
3B 72 69 0018
Line 1,633:
0071 12 .end main
</syntaxhighlight>
=={{header|VBA}}==
<
Sub DeleteFileOrDirectory()
Line 1,645:
'delete Directory
RmDir myPath
End Sub</
=={{header|VBScript}}==
<
oFSO.DeleteFile "input.txt"
Line 1,670:
fld.Delete
</syntaxhighlight>
=={{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.
<
File_Delete("input.txt", OK)
File_Rmdir("docs")
Line 1,680:
// In the root directory
File_Delete("/input.txt", OK)
File_Rmdir("/docs")</
=={{header|Visual Basic .NET}}==
Line 1,686:
{{works with|Visual Basic .NET|9.0+}}
<
IO.Directory.Delete("docs")
IO.Directory.Delete("docs", True) 'also delete files and sub-directories
Line 1,697:
'Root, platform independent
IO.Directory.Delete(IO.Path.DirectorySeparatorChar & "docs")
IO.File.Delete(IO.Path.DirectorySeparatorChar & "output.txt")</
=={{header|Wren}}==
Line 1,703:
Wren does not currently support the removal of directories.
<
File.delete("input.txt")
// check it worked
System.print(File.exists("input.txt"))</
{{out}}
Line 1,718:
{{works with|NASM|Linux}}
<
;syscall numbers for readability. :]
%define sys_rmdir 40
Line 1,764:
err_msg db "Something went wrong! :[",0xa
err_len equ $-err_msg
</syntaxhighlight>
=={{header|Yorick}}==
Yorick does not have a built-in function to recursively delete a directory; the rmdir function only works on empty directories.
<
remove, "/input.txt";
rmdir, "docs";
rmdir, "/docs";</
=={{header|zig}}==
<
const fs = std.fs;
Line 1,786:
try root.deleteFile("input.txt");
try root.deleteDir("docs");
}</
=={{header|zkl}}==
zkl doesn't have built ins to delete files or directories but you can let a shell do it:
<
0
zkl: System.cmd((System.isWindows and "del" or "unlink") + " /input.txt")
Line 1,802:
zkl: System.cmd("rm -r /docs")
rm: cannot remove ‘/docs’: No such file or directory
256</
{{omit from|Befunge}} <!-- No filesystem support -->
|