# Python 文件遍历(1)

稳定排序地遍历一个文件下的文件

```python
# -*- coding: UTF-8 -*-
import os

def ordered_list_dir(dir):
    # TODO(You): 请在此实现代码
    return entries

if __name__ == '__main__':
    entries = ordered_list_dir('./')
    for entry in entries:
        print(entry)
```

请选出下列能**正确**实现这一功能的选项。

## template

```python
import os


def ordered_list_dir(dir):
    entries = os.listdir(dir)
    entries.sort()
    return entries

if __name__ == '__main__':
    entries = ordered_list_dir('./')
    for entry in entries:
        print(entry)
```

## 答案

```python
def ordered_list_dir(dir):
    entries = os.listdir(dir)
    entries.sort()
    return entries
```

## 选项

### A

```python
def ordered_list_dir(dir):
    entries = os.listdir(dir)
    return entries
```

### B

```python
def ordered_list_dir(dir):
    entries = os.listdir(dir)
    return entries.sort()
```

### C

```python
def ordered_list_dir(dir):
    entries = os.path.listdir(dir)
    entries.sort()
    return entries
```
