Perl rmdir Function



Description

This function deletes the directory specified by EXPR, or $_ if omitted. Only deletes the directory if the directory is empty.

Syntax

Following is the simple syntax for this function −

rmdir EXPR

rmdir

Return Value

This function returns 0 on failure and 1 on success.

Example

Following is the example code showing its basic usage, create one directory testdir inside /tmp −

#!/usr/bin/perl -w

rmdir ("/tmp/testdir") || die ("error in deleting directory: $?");

When above code is executed, it produces the following result −

If directory is empty then it will be deleted
otherwise error message will be generated.
perl_function_references.htm
Advertisements