Delete a file: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
No edit summary
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(12 intermediate revisions by 7 users not shown)
Line 478:
 
=={{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}}
<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
.</syntaxhighlight>
 
Alternate method of deleting files using the <code>DELETE FILE</code> statement.
{{works with|Visual COBOL}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Delete-Files-2.
 
ENVIRONMENT DIVISION.
Line 508 ⟶ 494:
FD Local-File.
01 Local-Record PIC X.
 
FD Root-File.
01 Root-Record PIC X.
Line 515 ⟶ 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
.</syntaxhighlight>
 
=={{header|Common Lisp}}==
Line 748 ⟶ 749:
<pre>
Usage: furor rmdir.upu unnecessary_directory
</pre>
 
 
=={{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>
 
Line 947 ⟶ 980:
console.log("Done!");
})</syntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">"input.txt" fremove
"docs" fremove
"/input.txt" fremove
"/docs" fremove.</syntaxhighlight>
 
=={{header|Julia}}==
Line 996 ⟶ 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}}==
Line 1,250 ⟶ 1,313:
 
<syntaxhighlight lang="ocaml">Sys.remove "input.txt";;
Sys.remove "/input.txt";;</syntaxhighlight>
Sys.rmdir "docs";;
Sys.rmdir "/docs";;</syntaxhighlight>
 
with the Unix library:
Line 1,361 ⟶ 1,426:
rm("/docs");
}</syntaxhighlight>
 
=={{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}}==
Line 1,479 ⟶ 1,557:
system("rmdir docs")
</syntaxhighlight>
 
=={{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}}==
Line 1,734 ⟶ 1,820:
IO.Directory.Delete(IO.Path.DirectorySeparatorChar & "docs")
IO.File.Delete(IO.Path.DirectorySeparatorChar & "output.txt")</syntaxhighlight>
 
=={{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,739 ⟶ 1,841:
 
Wren does not currently support the removal of directories.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
File.delete("input.txt")
9,476

edits