zoukankan      html  css  js  c++  java
  • python——获取文件列表

     1 """--------------------------------------------------------
     2 <<获取文件列表>>
     3 (1) os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表。
     4 这个列表以字母顺序。 它不包括 '.''..' 即使它在文件夹中。只支持在
     5 Unix, Windows 下使用。
     6 (2) os.path.join(path1[, path2[, ...]])    把目录和文件名合成一个路径
     7 ---------------------------------------------------------"""
     8 import os
     9 data_dir = "datacn/dialog/"
    10 
    11 """获取文件列表"""
    12 def getRawFileList(path):
    13     """-------------------------
    14     files,names=getRawFileList(raw_data_dir)
    15     files: ['datacn/dialog/one.txt', 'datacn/dialog/two.txt']
    16     names: ['one.txt', 'two.txt']
    17     ----------------------------"""
    18     files = []
    19     names = []
    20     for f in os.listdir(path):
    21         if not f.endswith("~") or not f == "":      # 返回指定的文件夹包含的文件或文件夹的名字的列表
    22             files.append(os.path.join(path, f))     # 把目录和文件名合成一个路径
    23             names.append(f)
    24     return files, names
    25 
    26 files,names = getRawFileList(data_dir)
    27 print("files:", files)
    28 print("names:", names)
    E:MySoftAnaconda3envs	ensorFlowpython.exe E:/MySoft/pyCharm/RNN_ChattingRobot_Day/test1.py
    files: ['datacn/dialog/one.txt', 'datacn/dialog/two.txt']
    names: ['one.txt', 'two.txt']
    
    Process finished with exit code 0
    萍水相逢逢萍水,浮萍之水水浮萍!
  • 相关阅读:
    css添加方法
    node + vue 实现服务端单向推送消息,利用EventSource
    获取公众号openid,通过unionid 和小程序用户绑定起来
    小程序 构建npm
    powershell禁止系统运行脚本
    mongoose 删除
    mongoose 查询
    moogoose 更新
    小程序,用户授权手机号,node需要检验和解析
    小程序:支付的时候缺少参数:total_fee,支付失败
  • 原文地址:https://www.cnblogs.com/AIBigTruth/p/10721707.html
Copyright © 2011-2022 走看看