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
    萍水相逢逢萍水,浮萍之水水浮萍!
  • 相关阅读:
    SQL CHECKOUT
    Adobe CS4 " Licensing for this product has expired " FIX!!!
    sizeof()用法汇总
    Command
    EXP_FULL_DATABASE,IMP_FULL_DATABASE,DBA,CONNECT,RESOURCE
    inet_addr函数处理IP地址需要注意的问题 (转)
    Oracle:外键关联导致数据无法删除
    三范式
    Wireshark界面上展开数据帧
    我的HTML学习记录(三)
  • 原文地址:https://www.cnblogs.com/AIBigTruth/p/10721707.html
Copyright © 2011-2022 走看看