Description

This function checks whether a directory is empty.

Examples




https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=FSTest&cpanel_jsonapi_func=dirisempty&dir=%2Fhome%2Fcolin%2Fpublic_html&files_only=1&regex_ext=%2F.txt



$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Check if /home/user/public_html/subdomain/ is empty.
$check_directory = $cpanel->api2(
    'FSTest', 'dirisempty',
		array(        
			'dir'           => '/home/user/public_html/subdomain/', 
			'files_only'    => '1',
			'regex_ext'     => '\.txt',
   			) 
 );

 



my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Check if /home/user/public_html/subdomain/ is empty.
my $check_directory_ = $cpliveapi->api2(
    'FSTest', 'dirisempty',
    { 
			'dir'           => '/home/user/public_html/subdomain/', 
			'files_only'    => '1',
			'regex_ext'     => '\.txt',
	}
 );

 


 



cpapi2 --user=username FSTest dirisempty dir=%2Fhome%2Fuser%2Fpublic_html%2Fsubdomain%2F files_only=1 regex_ext=\.txt



{
  "cpanelresult": {
    "apiversion": 2,
    "func": "dirisempty",
    "data": [
      
    ],
    "event": {
      "result": 1
    },
    "module": "FSTest"
  }
}



Parameters

InputTypeDescriptionPossible valuesExample
dirstring

Required

The directory's file path.

Any valid file path./home/user/public_html/subdomain/
files_onlyBoolean

Whether to return only directories that contain files as not empty.

This parameter defaults to 0.

  • 1 — Display only directories that contain files.
  • 0 — Display all directories.
1
regex_extstring

A Perl Compatible Regular Expression (PCRE) that filters the results by file extension.

If you do not use this parameter, the function will not filter the results by file extension.

A valid PCRE.\.txt

Returns

ReturnTypeDescriptionPossible valuesExample
dataarrayWhether the specified directory exists and matches the files_only parameter's criteria.
  • 1 — Matches files_only.
  • N/A — Does not match files_only.
1
reasonstring

A reason for failure.


This function only returns a reason value if there was an error. 


A string that describes the error.This is an error message.
vresultBooleanWhether the function succeeded.
  • 1 — The function succeeded.
  • 0 — The function failed.
1