Delete a file: Difference between revisions

(Added 11l)
Line 21:
</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|Ada}}==
<lang ada>with Ada.Directories; use Ada.Directories;</lang>
Line 279 ⟶ 280:
<lang lisp>(let ((path (make-pathname :directory '(:relative "docs"))))
(cl-fad:delete-directory-and-files path))</lang>
 
=={{header|Component Pascal}}==
{{Works with|BlackBox Component Builder}}
Line 434 ⟶ 436:
Sleep
</lang>
 
=={{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.
<lang pascal>program deletion(input, output, stdErr);
const
rootDirectory = '/'; // might have to be altered for other platforms
inputTextFilename = 'input.txt';
docsFilename = 'docs';
var
fd: file;
begin
assign(fd, inputTextFilename);
erase(fd);
rmDir(docsFilename);
assign(fd, rootDirectory + inputTextFilename);
erase(fd);
rmDir(rootDirectory + docsFilename);
end.</lang>
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.
 
More convenient routines are <code>sysUtils.deleteFile</code> and <code>sysUtils.removeDir</code>.
Both accept strings and just return, whether the operation was successful.
 
=={{header|Gambas}}==
Line 727 ⟶ 755:
<lang logo>erasefile "input.txt
erasefile "/input.txt</lang>
 
=={{header|Lua}}==
<lang lua>os.remove("input.txt")
Line 937 ⟶ 966:
 
=={{header|Pascal}}==
''See [[Delete_a_file#Delphi|Delphi]] or [[#Free Pascal|Free DelphiPascal]]''
 
=={{header|Perl}}==
Line 1,227 ⟶ 1,256:
<lang stata>erase input.txt
rmdir docs</lang>
 
=={{header|Tcl}}==
 
Line 1,242 ⟶ 1,272:
" docs" remove
" input.txt" remove</lang>
 
=={{header|TUSCRIPT}}==
<lang tuscript>
Line 1,263 ⟶ 1,294:
f.delete "/input.txt"
f.delete "/docs"</lang>
 
=={{header|VAX Assembly}}==
<lang VAX Assembly>74 75 70 6E 69 20 65 74 65 6C 65 64 0000 1 dcl: .ascii "delete input.txt;,docs.dir;"
149

edits