# 文件或目录信息
<subtitle>获取文件或目录的详细信息。</subtitle>

您可以使用 `files.get_info()` 方法获取文件或目录的信息。返回的信息包括文件名、类型和路径等。

文件还可以携带自定义的用户定义元数据，它会在 `metadata` 字段中返回——参阅 [自定义元数据](/docs/agent-sandbox/filesystem/metadata.md)。

## 获取文件信息

```python
from ucloud_sandbox import Sandbox

sandbox = Sandbox.create()

# 创建新文件
sandbox.files.write('test_file', 'Hello, world!')

# 获取文件信息
info = sandbox.files.get_info('test_file')

print(info)
# EntryInfo(
#   name='test_file.txt',
#   type=<FileType.FILE: 'file'>,
#   path='/home/user/test_file.txt',
#   size=13,
#   mode=0o644,
#   permissions='-rw-r--r--',
#   owner='user',
#   group='user',
#   modified_time='2025-05-26T12:00:00.000Z',
#   symlink_target=None
# )
```

## 获取目录信息

```python
from ucloud_sandbox import Sandbox

sandbox = Sandbox.create()

# 创建新目录
sandbox.files.make_dir('test_dir')

# 获取目录信息
info = sandbox.files.get_info('test_dir')

print(info)
# EntryInfo(
#   name='test_dir',
#   type=<FileType.DIR: 'dir'>,
#   path='/home/user/test_dir',
#   size=0,
#   mode=0o755,
#   permissions='drwxr-xr-x',
#   owner='user',
#   group='user',
#   modified_time='2025-05-26T12:00:00.000Z',
#   symlink_target=None
# )
```
