> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: File System
icon: folder-tree
---

# <ApiPageIcon icon="folder-tree" />File System

<ApiExposes data="[{&#x22;k&#x22;:&#x22;NAMESPACE&#x22;,&#x22;c&#x22;:&#x22;fn&#x22;,&#x22;s&#x22;:&#x22;filesystem&#x22;,&#x22;h&#x22;:&#x22;#filesystem&#x22;},{&#x22;k&#x22;:&#x22;OBJECT&#x22;,&#x22;c&#x22;:&#x22;method&#x22;,&#x22;s&#x22;:&#x22;filesystem.Info.Result&#x22;,&#x22;h&#x22;:&#x22;#filesysteminforesult&#x22;}]" />

## filesystem<ApiTag label="global table" />

Provides access to the game's working directory at `%steamdir%/steamapps/cs2/game/bin/win64/`,
the SearchPaths at `game/csgo/`, `game/core/`, `csgo_addons`, and `csgo_community_addons`,
and the directory used by `cloud.ReadResource`. Attempting to access any other paths will throw an error.

Paths for the game's directories should be relative paths.

See [https://developer.valvesoftware.com/wiki/VPK\_(file\_format)](https://developer.valvesoftware.com/wiki/VPK_\(file_format\)) for how game content is managed by CS2.

The files in the path returned by `cloud.ReadResource` cannot be modified. `filesystem.List` will show
cloud files that are not yet extracted, and `filesystem.Info` will return the time the cloud script was modified at.

<ApiMembers>
  <ApiMember kind="fn" name="filesystem.Read" summary="Reads a file and returns all of its contents. If the file is not in the working directory, the SearchPaths are checked. Returns **nil** if the file cannot be opened." args="path, is_binary?" sig="[{&#x22;s&#x22;:&#x22;filesystem.Read&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;path&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;is_binary&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;?&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;?&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;path&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The path to the file, relative to the working directory.&#x22;},{&#x22;n&#x22;:&#x22;is_binary&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;d&#x22;:&#x22;Whether to read the file in binary mode. The default is `false`.&#x22;,&#x22;o&#x22;:true}]" nodiscard />

  <ApiMember kind="fn" name="filesystem.Write" summary="Writes `contents` to a file and replaces any content that the file already has. If the file cannot be opened in the working directory, the SearchPaths are tried. Returns `true` if all of the data was written, and `false` otherwise." args="path, contents, is_binary?" sig="[{&#x22;s&#x22;:&#x22;filesystem.Write&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;path&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;contents&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;is_binary&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;path&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The path to the file, relative to the working directory.&#x22;},{&#x22;n&#x22;:&#x22;contents&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The data to write.&#x22;},{&#x22;n&#x22;:&#x22;is_binary&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;d&#x22;:&#x22;Whether to write the file in binary mode. The default is `false`.&#x22;,&#x22;o&#x22;:true}]" />

  <ApiMember kind="fn" name="filesystem.Delete" summary="Deletes a file. If the file does not exist, nothing happens. Throws an error if the file exists but cannot be deleted." args="path" sig="[{&#x22;s&#x22;:&#x22;filesystem.Delete&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;path&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;}]" params="[{&#x22;n&#x22;:&#x22;path&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The path to the file, relative to the working directory.&#x22;}]" />

  <ApiMember kind="fn" name="filesystem.Folder" summary="Creates a directory at the given path. If the directory already exists, nothing happens. The parent directory must already exist, or an error is thrown." args="path" sig="[{&#x22;s&#x22;:&#x22;filesystem.Folder&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;path&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;}]" params="[{&#x22;n&#x22;:&#x22;path&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The path of the directory to create, relative to the working directory.&#x22;}]" />

  <ApiMember kind="fn" name="filesystem.List" summary="Returns the names of the entries in a directory. You can pass a wildcard pattern to keep only the names that match it. In the pattern, `*` matches any number of characters and `?` matches exactly one character." args="path, filter?" sig="[{&#x22;s&#x22;:&#x22;filesystem.List&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;path&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;filter&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;path&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The path to the directory, relative to the working directory.&#x22;},{&#x22;n&#x22;:&#x22;filter&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The wildcard pattern that names must match. If it is not given, all names are returned.&#x22;,&#x22;o&#x22;:true}]" nodiscard>
    <ApiNotes>
      Throws an error if the path is not an existing directory.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="filesystem.Info" summary="Returns the times and the size of a file. Throws an error if the file does not exist." args="path" sig="[{&#x22;s&#x22;:&#x22;filesystem.Info&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;path&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;filesystem.Info.Result&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/data/filesystem#filesysteminforesult&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;filesystem.Info.Result&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/data/filesystem#filesysteminforesult&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;path&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}],&#x22;d&#x22;:&#x22;The path to the file, relative to the working directory.&#x22;}]" nodiscard />
</ApiMembers>

## filesystem.Info.Result<ApiTag label="object type" />

The file information returned by `filesystem.Info`.

<ApiMembers>
  <ApiMember kind="prop" name="filesystem.Info.Result.atime" summary="The time of the last access, as a Unix timestamp." ret="[[{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]]" />

  <ApiMember kind="prop" name="filesystem.Info.Result.ctime" summary="The time of creation, as a Unix timestamp." ret="[[{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]]" />

  <ApiMember kind="prop" name="filesystem.Info.Result.mtime" summary="The time of the last modification, as a Unix timestamp." ret="[[{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]]" />

  <ApiMember kind="prop" name="filesystem.Info.Result.size" summary="The size of the file in bytes." ret="[[{&#x22;s&#x22;:&#x22;int64_t&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#int64_t&#x22;}]]" />
</ApiMembers>
