# cPanel API 2 Functions - Fileman::listfiles Warning: The cPanel API 2 system is deprecated. We **strongly** recommend that you use [UAPI](/cpanel/introduction) instead of cPanel API 2. ## Description This function lists a directory's files and their attributes. Warning: This function is **deprecated** as of cPanel and WHM version 11.40 and later. We **strongly** recommend that you use the following [UAPI](/cpanel/introduction/) functions instead of this function: - [`Fileman::get_file_information`](/openapi/cpanel/operation/get_file_information/) — This function returns the information for a specified file or directory. - [`Fileman::list_files`](/openapi/cpanel/operation/list_files/) — This function returns a sorted list of files and directories. Important: When you disable the [*File Storage* role](https://docs.cpanel.net/knowledge-base/general-systems-administration/how-to-use-server-profiles/#roles), the system **disables** this function. ## Examples WHM API (JSON) ```undefined syntaxhighlighter-pre https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=listfiles&checkleaf=1&dir=%2Fhome%2Fuser&filelist=1&filepath=filelist-A&needmime=1&showdotfiles=1&types=dir%20%7C%20file ``` Note: For more information, read our [Calls from the WHM API](/whm/use-whm-api-to-call-cpanel-api-and-uapi) documentation. LiveAPI PHP Class ```undefined syntaxhighlighter-pre $cpanel = new CPANEL(); // Connect to cPanel - only do this once. // List files in /home/user/public_html. $list_files = $cpanel->api2( 'Fileman', 'listfiles', array( 'checkleaf' => '1', 'dir' => '/home/user/public_html/', 'filelist' => '1', 'filepath-*' => 'filepath-myfile', 'needmime' => '1', 'showdotfiles' => '1', 'types' => 'dir|file', ) ); ``` Note: For more information, read our [Guide to the LiveAPI System](/guides/guide-to-the-liveapi-system/#guide-to-the-liveapi-system). LiveAPI Perl Module ```undefined syntaxhighlighter-pre my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once. # Search for directories that begin with /home/user/public_html. my $search_directories = $cpliveapi->api2( 'Fileman', 'autocompletedir', { 'checkleaf' => '1', 'dir' => '/home/user/public_html/', 'filelist' => '1', 'filepath-*' => 'filepath-myfile', 'needmime' => '1', 'showdotfiles' => '1', 'types' => 'dir|file', } ); ``` Note: For more information, read our [Guide to the LiveAPI System](/guides/guide-to-the-liveapi-system/#guide-to-the-liveapi-system). cPanel Tag System (deprecated) Warnings: - cPanel tags are **deprecated**. We **strongly** recommend that you **only** use the [LiveAPI](/guides/guide-to-the-liveapi-system) system to call the cPanel APIs. Examples are **only** present in order to help developers move from the old cPanel tag system to our [LiveAPI](/guides/guide-to-the-liveapi-system). - cPanel API 2 calls that use cPanel tags vary in code syntax and in their output. - For more information, read our [Deprecated cPanel Tag Usage](/cpanel-api-2/cpanel-api-2-deprecate-cpanel-tag-usage/) documentation. Command Line ```undefined syntaxhighlighter-pre cpapi2 --user=username Fileman autocompletedir checkleaf=1 dir=%2Fhome%2Fuser%2Fpublic_html%2F filelist=1 filepath-*=filepath-myfile needmime=1 showdotfiles=1 types=dir%7Cfile ``` div Notes: - You **must** URI-encode values. - `username` represents your account-level username. - You **must** include the `--user=username` option. - For more information and additional output options, read our [Guide to cPanel API 2](/cpanel-api-2/) documentation or run the `cpapi2 --help` command. - If you run CloudLinux™, you **must** use the full path of the `cpapi2` command: ```undefined syntaxhighlighter-pre /usr/local/cpanel/bin/cpapi2 ``` br Output (JSON) ```undefined syntaxhighlighter-pre { "cpanelresult": { "apiversion": 2, "func": "listfiles", "files": [{ "ctime": "1371711650", "uid": "508", "mode": "33184", "mtime": "1371711650", "isleaf": "1", "mimename": "homeb", "file": "cpbackup-exclude.conf", "path": "/home/example", "nicemode": "0640", "humansize": "1 byte", "size": "1", "fullpath": "/home/example/cpbackup-exclude.conf", "type": "file", "mimetype": "text/plain", "exists": "1", "gid": "508" }], "dirs": [{ "ctime": "1377179101", "uid": "", "mode": "16872", "isleaf": "1", "mimename": "homeb", "mtime": "1371591601", "file": "access-logs", "path": "/home/example", "nicemode": "0750", "humansize": "4 KB", "size": "4096", "fullpath": "/home/example/access-logs", "type": "dir", "mimetype": "text/plain", "exists": "1", "gid": "508" }], "event": { "result": 1 }, "module": "Fileman" } } ``` Note: Use cPanel's *[API Shell](https://docs.cpanel.net/cpanel/advanced/api-shell-for-cpanel)* interface (*cPanel >> Home >> Advanced >> API Shell*) to directly test cPanel API calls. ## Parameters table thead tr th Parameter th Type th Description th Possible values th Example tbody tr td p code checkleaf td em Boolean td p Whether to add the code isleaf parameter to the output key. p This parameter defaults to code 0 . td ul li code 1 — Add the code isleaf parameter to the output key. li code 0 — Do strong not add the code isleaf parameter to the output key. td code 1 tr td code dir td em string td p The directory. strong p This parameter defaults to the user's code /home directory. td A valid directory name. td code public_html tr td code filelist td em Boolean td p Whether to search for keys that begin with code filepath-* . p This parameter defaults to code 0 . td ul li code 1 — Search for keys that begin with code filepath-* li code 0 — Search for keys that do strong not begin with code filepath-* td code 1 tr td code filepath-* td em string td p Which files to list with the output, if the code filelist parameter is code 1 . p Each key indicates a file to view. p This parameter defaults to an empty string. td Any valid filename. td code filepath-myfile tr td code needmime td em Boolean td p Whether to return the code mimename and code mimetype parameters. p This parameter defaults to code 0 . td ul li code 1 — Return the code mimename and code mimetype parameters. li code 0 — Do strong not return the code mimename and code mimetype parameters. td code 1 tr td code showdotfiles td em Boolean td p Whether to add dotfiles to the output keys. p This parameter defaults to code 0 . td ul li code 1 — Add dotfiles to the output keys. li code 0 — Do not add dotfiles to the output keys. td code 1 tr td code types td em string td p The types of files to return. p If you do not use this parameter, the function returns all file types. td One or more valid file types, separated by pipe characters. td code dir|file ## Returns table thead tr th strong Return th strong Type th strong Description th strong Possible values th strong Example tbody tr td code ctime td em integer td The file's creation time. td A a Unix time stamp . td code 1371711650 tr td code uid td em integer td The file owner's user ID. td p A valid user ID on the server. td code User tr td code mode td em string td The file's permissions. td A set of file permissions, in a textual representation format. td code 16877 tr td code mtime td em integer td The file's last modification time. td A Unix time stamp. td code 1411211655 tr td code isleaf td em Boolean td Whether the domain contains subdirectories. td ul li code 0 — The directory contains subdirectories. li code 1 — The directory does strong not contain subdirectories. td code 1 tr td code mimename td em string td The file's MIME name. td A valid MIME name. td code homeb tr td code file td em string td The file's name. td A valid filename. td code public_html tr td code path td em string td p The path to the file. td p A valid absolute file path. p This value does not include the file or directory name. td code /home/example/cpbackup-exclude.conf tr td code nicemode td em integer td The file's permissions. td A set of file permissions, in a octal notation format. td code 0777 tr td code humansize td em string td The formatted size of the file. td A positive integer and a unit of measure in megabytes ( code MB ), kilobytes ( code KB ), or gigabytes ( code GB ). td code 4KB tr td code size td em integer td The size of the file. td A positive integer, in bytes. td code 4096 tr td code fullpath td em string td p The path to the file. td An absolute file path that includes the file or directory name. td code home/user/public_html tr td code type td em string td The item type. td ul li code file li code dir li code char li code block li code fifo li code link li code socket td code file tr td code mimetype td em string td The file's MIME type. td A valid MIME type. td code text/plain tr td code gid td em integer td The file owner's system group ID. td A positive integer. td code 508 tr td code reason td em string td p A reason for failure. p This function only returns a code reason value if an error occurred. td A string that describes the error. td code This is an error message. tr td code result td em Boolean td p Whether the function succeeded. td ul li code 1 — The function succeeded. li code 0 — The function failed. td code 1