# `load`, `rload`

_Load binary data from a file or directory_

## `load`

_Load binary data from a file_
```syntax
load x     load[x]
```

Where `x` is

- a symbol atom or vector matching the names of datafiles (with no extension) in the current directory, reads the datafiles and assigns the values to global variables of the same names, which it returns
- a filesymbol atom or vector for datafiles (with no extension), reads the datafiles and assigns the values to global variables of the same names, which it returns
- a filesymbol for a directory, creates a global dictionary of the same name and within that dictionary recurses on any datafiles the directory contains

> **Note — Binary data only**
>
>
> `load` signals an error if the file is not a KDB-X data file. It does not read the text formats that [`save`](save.md) can write; for those, use [File Text](file-text.md).
>
```q
q)t:([]x: 1 2 3; y: 10 20 30)
q)save`t             / save to a binary file (same as `:t set t)
`:t
q)delete t from `.   / delete t
`.
q)t                  / not found
't
  [0]  t                  / not found
       ^

q)load`t             / load from a binary file (same as t:get `:t)
`t
q)t
x y
----
1 10
2 20
3 30
```

Load a directory of datafiles into a dictionary:
```q
q)s:([s:`s1`s2]name:`smith`jones)
q)p:([p:`p1`p2]color:`red`green)
q)`:cb/p set p
`:cb/p
q)`:cb/s set s
`:cb/s
q)load `cb
`cb
q)key cb
`s#`p`s
q)cb `s
s | name
--| -----
s1| smith
s2| jones
```

> **Warning — Operating systems may create hidden files, such as `.DS_Store`, that block `load`.**
>
>
## `rload`

_Load a splayed table from a directory_
```syntax
rload x     rload[x]
```

Where `x` is the table name as a symbol, `rload` reads the table from the directory of the same name. `rload` is the converse of [`rsave`](save.md#rsave).
```q
q)sp:([]qty:300 200 400;px:1 2 3f)
q)rsave `sp           / save splayed table
`:sp/
q)delete sp from `.
`.
q)rload `sp           / load splayed table
`sp
q)sp
qty px
------
300 1
200 2
400 3
```

> **Tip — Use `get` for more flexibility**
>
>
> [`get`](get.md) is the usual, more general way to do this: it lets you give the table a different name from its source directory.
>
> `get` returns a splayed table that refers to the directory, rather than a copy of the table in memory, so it doesn't match the result of `rload` with [`~`](match.md). Its rows do:
>
> ```q
> q)sp~get `:sp/
> 0b
> q)sp~select from get `:sp/
> 1b
> ```
>
----

[`save`, `rsave`](save.md),
[`.Q.dsftg`](dotq.md#dsftg-load-process-save) (load process save),
[`.Q.fps`](dotq.md#fps-pipe-streaming) (pipe streaming),
[`.Q.fs`](dotq.md#fs-file-streaming) (file streaming),
[`.Q.fsn`](dotq.md#fsn-file-streaming) (file streaming with chunks),
[`.Q.v`](dotq.md#v-value) (get splayed table)


[File system](files.md)


_Q for Mortals_
[§11.2 Save and Load on Tables](../learn/q4m/11_IO.md#112-save-and-load-on-tables)
