directory delete ...

Prev Next

Function Names

directory delete, directory delete all, directory delete silently

Description

These functions delete specified directories (including their files) and come in following flavors:
directory delete will assert an exception if the directory cannot be deleted (e.g. directory not found, directory not empty, access restrictions, etc.) Execution will stop immediately.
directory delete silently will delete the directories 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. directory delete all tries to delete all directories and skips the ones which cannot be created. Here, the number of successfully deleted directories 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
string directory name

Specify directory name. Add path name in front if needed. With indirect parameter passing enabled, the directories to delete can also be provided in one set. Example: directory delete( { directory1, directory2, .. } );

Return value

TypeDescription
numeral or string Feedback

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

Exceptions

Directory not found
Directory not empty
Directory not accessible
Attempting to delete a file

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_directory_delete.b4p in B4P_Examples.zip. Decompress before use.

See also

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