python 中列出指定目录中文件的绝对路径

 

001、

[root@PC1 test2]# ls
a.txt  b.txt  test.py  x.csv  y.csv
[root@PC1 test2]# pwd
/home/test2
[root@PC1 test2]# cat test.py    ## 脚本
#!/usr/bin/python

import os

pwd="/home/test2"
for i in os.listdir(pwd):
    print(pwd + "/" + i)
[root@PC1 test2]# python test.py     ## 执行结果
/home/test2/a.txt
/home/test2/b.txt
/home/test2/x.csv
/home/test2/y.csv
/home/test2/test.py

 

posted @ 2022-06-07 20:45  小鲨鱼2018  阅读(127)  评论(0编辑  收藏  举报