file delete ...

Prev Next

Function Names

file delete, file delete all, file delete silently

Description

These functions delete specified files and come in following flavors:
file delete will assert an exception if file cannot be deleted (e.g. file not found, locked, access restrictions, etc.) Execution will stop immediately.
file delete silently will delete the files until a first failure is encountered. In this case, the applicable one of the short error messages on directories and files will be returned. If no errors have been encountered, "OK" will be returned.
file delete all tries to delete al files and skips the ones which cannot be created. Here, the number of successfully deleted files will be returned.

Call as: procedure or function

Restrictions

Indirect parameter passing is enabled.
Wildcards are not supported here

Parameter count

Min 0

Parameters

No.TypeDescription
1, etc.
input
parameter set or string file name(s)

Specify file name. Add path name in front if needed. With indirect parameter passing enabled, the files to delete can also be provided in one parameter set. Example: file delete( { file1.txt, file.txt, .. } );

Return value

TypeDescription
numeral or string Feedback

file delete: Always "OK", because all errors cause exceptions.
file delete silently: "OK", or short error messages on directories and files.
file delete all: Number of successful operations (files deleted) is returned.

Exceptions

File not found
File locked by another application
File not accessible
Attempting to delete a directory

Examples

      file copy ( {3 : Example_Program.b4p}, { Test123.txt, Test456.txt, Test789.txt } );
      print( file delete all ( Test123.txt, TestXXX.txt, Test456.txt ), " / " ); // Returns 2
      print( file delete ( Test789.txt ), " / " ); // Returns OK
      echo( file delete silently ( Test789.txt )); // Returns "File not found"

      files[] = { Test123.txt, Test456.txt, Test789.txt };
      file copy ( {3 : Example_Program.b4p}, files[] );
      echo( file delete all ( files[] ) ); // Returns 3

Output

2 / OK / File not Found
3
Try it yourself: Open LIB_Function_file_delete.b4p in B4P_Examples.zip. Decompress before use.

See also

directory delete ... Functions
file delete multiple/recursive ... Functions