Python 3.6 :os.listdir()与os.path.join()方法的使用

os.listdir() 方法

作用:

os.listdir() 方法 : 返回指定文件夹包含的文件或文件夹名字的列表。该列表顺序以字母排序。

语法:

listdir()方法的语法如下:

os.listdir(path)

参数:

  • path–需要列出的目录路径

实例:

F:\data\input 文件夹下:
这里写图片描述

import os 
path = 'F:\\data\\input'
dirs = os.listdir(path)

# 输出所有文件和文件夹
for file in dirs:
   print(file)

output:

hamlet.txt
hamlet2.txt
input.txt
test
userurl_20150911.tdl

os.path.join() 函数

作用:

os.path.join() : 将多个路径组合后返回

语法:

 os.path.join(path1[,path2[,......]])

实例:

import os 
path_root = 'F:\\data\\input'
dirs = os.listdir(path_root)

# 输出所有文件和文件夹
for file in dirs:
    path = os.path.join(path_root)
    path_test = os.path.join(path)
    #print(path)
    print(path_test)
#也可以直接进行将多个路径组合后返回
p = os.path.join('F:\\data\\input','test')
print(p)

output:

F:\data\input\hamlet.txt
F:\data\input\hamlet2.txt
F:\data\input\input.txt
F:\data\input\test
F:\data\input\userurl_20150911.tdl
F:\data\input\test  #直接将多个路径组合后返回
WARNING:tensorflow:From /root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term 2025-07-26 19:39:44.736818: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1 2025-07-26 19:39:44.817833: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: pciBusID: 0000:39:00.0 name: NVIDIA GeForce RTX 4090 computeCapability: 8.9 coreClock: 2.52GHz coreCount: 128 deviceMemorySize: 23.55GiB deviceMemoryBandwidth: 938.86GiB/s 2025-07-26 19:39:44.818047: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library &#39;libcudart.so.10.1&#39;; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory 2025-07-26 19:39:44.818085: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library &#39;libcublas.so.10&#39;; dlerror: libcublas.so.10: cannot open shared object file: No such file or directory 2025-07-26 19:39:44.819189: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10 2025-07-26 19:39:44.819444: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10 2025-07-26 19:39:44.819488: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library &#39;libcusolver.so.10&#39;; dlerror: libcusolver.so.10: cannot open shared object file: No such file or directory 2025-07-26 19:39:44.819520: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library &#39;libcusparse.so.10&#39;; dlerror: libcusparse.so.10: cannot open shared object file: No such file or directory 2025-07-26 19:39:44.819552: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library &#39;libcudnn.so.7&#39;; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory 2025-07-26 19:39:44.819560: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2025-07-26 19:39:44.819885: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA 2025-07-26 19:39:44.850997: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2000000000 Hz 2025-07-26 19:39:44.856714: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7effe8000b60 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2025-07-26 19:39:44.856739: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 2025-07-26 19:39:44.858559: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix: 2025-07-26 19:39:44.858573: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108] WARNING:tensorflow:From /root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/layers/layers.py:1089: Layer.apply (from tensorflow.python.keras.engine.base_layer_v1) is deprecated and will be removed in a future version. Instructions for updating: Please use `layer.__call__` method instead. loaded ./checkpoint/decom_net_train/model.ckpt loaded ./checkpoint/illumination_adjust_net_train/model.ckpt No restoration pre model! (480, 640, 3) (680, 720, 3) (415, 370, 3) Traceback (most recent call last): File "evaluate.py", line 73, in <module> eval_low_im = load_images(eval_low_data_name[idx]) File "/root/Python/KinD-master/KinD-master/utils.py", line 63, in load_images im = Image.open(file) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/PIL/Image.py", line 2975, in open fp = builtins.open(filename, "rb") IsADirectoryError: [Errno 21] Is a directory: &#39;./test/results&#39;
最新发布
07-27
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值