# 文件或目录信息
<subtitle>获取 Volume 中文件或目录的元数据、检查路径是否存在，以及修改权限。</subtitle>

使用 `get_info()` 方法获取 Volume 中文件或目录的信息。

### 获取文件信息

```python
from ucloud_sandbox import Volume

volume = Volume.connect('volume-id')

# 创建一个新文件
volume.write_file('/test_file.txt', 'Hello, world!')

# 获取文件信息
info = volume.get_info('/test_file.txt')

print(info)
# VolumeEntryStat(
#   name='test_file.txt',
#   type='file',
#   path='/test_file.txt',
#   size=13,
#   mode=0o644,
#   uid=0,
#   gid=0,
#   atime=datetime(2025, 5, 26, 12, 0, 0),
#   mtime=datetime(2025, 5, 26, 12, 0, 0),
#   ctime=datetime(2025, 5, 26, 12, 0, 0),
# )
```

### 获取目录信息

```python
from ucloud_sandbox import Volume

volume = Volume.connect('volume-id')

# 创建一个新目录
volume.make_dir('/test_dir')

# 获取目录信息
info = volume.get_info('/test_dir')

print(info)
# VolumeEntryStat(
#   name='test_dir',
#   type='directory',
#   path='/test_dir',
#   size=0,
#   mode=0o755,
#   uid=0,
#   gid=0,
#   atime=datetime(2025, 5, 26, 12, 0, 0),
#   mtime=datetime(2025, 5, 26, 12, 0, 0),
#   ctime=datetime(2025, 5, 26, 12, 0, 0),
# )
```

### 检查路径是否存在

使用 `exists()` 方法检查 Volume 中的文件或目录是否存在。

```python
from ucloud_sandbox import Volume

volume = Volume.connect('volume-id')

file_exists = volume.exists('/test_file.txt')
print(file_exists)  # True 或 False
```

### 修改元数据

使用 `update_metadata()` 方法修改文件或目录的用户 ID、组 ID 和权限模式。

```python
from ucloud_sandbox import Volume

volume = Volume.connect('volume-id')

volume.write_file('/test_file.txt', 'Hello, world!')

updated = volume.update_metadata('/test_file.txt', uid=1000, gid=1000, mode=0o600)

print(updated)
# VolumeEntryStat(
#   name='test_file.txt',
#   type='file',
#   path='/test_file.txt',
#   size=13,
#   mode=0o600,
#   uid=1000,
#   gid=1000,
#   ...
# )
```
