Name: files

Type: function

Syntax: the [{ detailed | long }] files

Syntax: files([<targetFolder>[, <outputKind>]])

Summary:
List the files in a folder.

Introduced: 1.0

OS: mac, windows, linux, ios, android, html5

Platforms: desktop, server, mobile

Security: disk

Example:
put files(specialFolderPath("documents")) into field "Current Docs"
sort lines of field "Current Docs" international

Example:
local tTotalSize
repeat for each line tFileInfo in the detailed files
   add item 3 of tFileInfo to tTotalSize
end repeat
answer merge("The files in the current folder use" && \
      "[[tTotalSize]] bytes")

Example:
local tDiskContents
put the files & return & the folders into \
      tDiskContents["the defaultFolder"]
filter tDiskContents["the defaultFolder"] without ".."

Parameters:
targetFolder (String):
The folder path to search.

outputKind (enum):
- empty: Use the short form
- "detailed": Use the long/detailed form

Returns (String):
A list of file names or file information, with one
file per line.

Description:
<Return(glossary)> a list of <file|files> in the <targetFolder>, with
one file per line.  If no <targetFolder> is specified, list the files
in the <current folder>.

<folder(glossary)|Folders> are not included in the list.  To get a
list of folders, use the <folders> function.

<alias|Aliases> (on OS X systems), <symbolic links|symbolic links> (on
Linux systems) and <shortcut|shortcuts> (on Windows systems) are
included in the list only if they refer to a <file>.

> *Note:* The order that files are listed is platform-dependent.  The
> order may vary between <platform|platforms>, between filesystems,
> and even between consecutive calls to the <files> function.  If you
> need a sorted list, use the <sort> command.

### Short form

When the <files> is called as a <function>, or without the `long` or
`detailed` modifiers, it <return(glossary)|returns> only the <file>
names as a string with one file name per line.

> *Note:* On some <platform|platforms>, file names are permitted to
> include the <return(constant)|linefeed> character.  Such a file name
> would be split across more than one line of the string returned by
> the <files> <function>.

### Long form

`the long files` and `the detailed files` are synonyms.  When 
the <files> <function> is called in this form, the <return(glossary)>
value is a list of files with detailed file attributes.

Each line in the return value is a comma-separated list of file
attributes, as follows:

1. **Name**.  The file name is URL-encoded.  To obtain the name as
   plain text, use the <URLDecode> function.
2. **Size**, in bytes.  On OS X systems, this is the size of the 
   <data fork>.
3. **Resource fork size**, in bytes.  (OS X only).
4. **Creation date**, in seconds.  (OS X and Windows only).
5. **Last modification date**, in seconds.
6. **Last access date**, in seconds.
7. **Last backup date**, in seconds.
8. **User owner**.  (Linux and OS X only).
9. **Group owner**.  (Linux and OS X only).
10. **Permissions**. (Linux and OS X only; see note).
11. **Creator and <fileType|file type>**.  (OS X only).


Any attribute that is not relevant to the current <platform> is left
empty.

The access permissions consist of three octal digits, in the same form
used for the <umask> property.

> *Note:* On Windows, the permissions are always reported as "777".

Changes:
The <long> form was introduced in version 1.1.
The optional <targetFolder> argument for the function call form was
introduced in version 8.1.

References: sort (command), return (constant), folders (function),
specialFolderPath (function), alias (glossary), current folder (glossary),
data fork (glossary), folder (glossary), function (glossary),
platform (glossary), return (glossary), resource fork (glossary),
shortcut (glossary), symbolic link (glossary), defaultFolder (property),
umask (property), long (keyword)

Tags: file system

