Main Content

isfile

Determine if input is file

Description

result = isfile(filename) returns 1 if filename is a file located on the specified path or in the current folder. Otherwise, isfile returns 0.

Examples

collapse all

Check if the input myfile1.txt is a file. A result of 1 indicates that myfile1.txt is a file.

result = isfile('myfile1.txt')
result = logical
   1

Create the folder myfolder, then check if myfolder is a file. A result of 0 indicates that myfolder is not a file.

mkdir myfolder;
result = isfile('myfolder')
result = logical
   0

Check if the inputs myfile1.txt and myfolder are files. A result of [1 0] indicates that myfile1.txt is a file and myfolder is not a file.

result = isfile(["myfile1.txt", "myfolder"])
result = 1×2 logical array
   1   0

Input Arguments

collapse all

Filename, specified as a string array, character vector, or cell array of character vectors. For a local file, filename can include a relative path, but the relative path must be in the current folder. Otherwise, filename must include a full path.

For files and folders at a remote location, you must specify the full path as a uniform resource locator (URL). Internet URLs must include the protocol type "http://" or "https://". For more information, see Work with Remote Data.

Limitations

  • MATLAB® does not support internet URLs that require authentication.

  • MATLAB Online™ supports internet URLs associated with Microsoft® OneDrive™ files and folders, while the installed version of MATLAB supports only local OneDrive files.

Extended Capabilities

Version History

Introduced in R2017b

expand all