`
ppju
  • 浏览: 78250 次
  • 性别: Icon_minigender_1
  • 来自: 西安
文章分类
社区版块
存档分类
最新评论

python to print all files

阅读更多
 
 
   1. def find_file_by_pattern(pattern='.*', base=".", circle=True):  
   2.     '''''查找给定文件夹下面所有 '''  
   3.     re_file = re.compile(pattern)  
   4.     if base == ".":  
   5.         base = os.getcwd()  
   6.           
   7.     final_file_list = []  
   8.     print base  
   9.     cur_list = os.listdir(base)  
  10.     for item in cur_list:  
  11.         if item == ".svn":  
  12.             continue  
  13.           
  14.         full_path = os.path.join(base, item)  
  15.         if full_path.endswith(".doc") or \  
  16.             full_path.endswith(".bmp") or \  
  17.             full_path.endswith(".wpt") or \  
  18.             full_path.endswith(".dot"):  
  19.             continue  
  20.               
  21.         # print full_path  
  22.         bfile = os.path.isfile(item)  
  23.         if os.path.isfile(full_path):  
  24.            if re_file.search(full_path):  
  25.                final_file_list.append(full_path)  
  26.         else:  
  27.            final_file_list += find_file_by_pattern(pattern, full_path)  
  28.     return final_file_list  

分享到:
评论

相关推荐

    python读取不同格式的文件

    student1.tsv[all files存储];student1.txt);第二步:采用Python导入,如 import pandas as pd student2=pd.read_csv('d:\Program Files\python3x\Temp\student1.txt',sep='|',index_col='ID') print(student2)

    python3.6.5参考手册 chm

    New Features Added to Python 2.7 Maintenance Releases PEP 434: IDLE Enhancement Exception for All Branches PEP 466: Network Security Enhancements for Python 2.7 Acknowledgements What’s New in ...

    Beginning Python (2005).pdf

    Using Python to Transform XML Using XSLT 294 Try It Out: Transforming XML with XSLT 294 Putting It All Together: Working with RSS 296 RSS Overview and Vocabulary 296 Making Sense of It All 296 ...

    Python实现FTP

    print("Files in directory:", files) # 上传文件 with open("local_file.txt", "rb") as f: ftp.storbinary("STOR remote_file.txt", f) # 将本地文件上传至服务器 # 下载文件 with open("remote_file.txt...

    Python 语言实现的抓取网页内容与列文件目录

    links = soup.find_all('a') for link in links: print(link.get('href')) ``` 接下来,我们讨论如何在Python中列出文件目录。这通常涉及到os和os.path模块。`os.listdir()`函数可以返回指定路径下的所有文件和...

    python读写rar文件的模块

    print(file) ``` 3. **提取RAR文件**: 要提取RAR文件中的特定文件或所有文件,可以使用`extract()`或`extractall()`方法。`extract()`用于提取单个文件,`extractall()`用于提取所有文件到指定目录。 ```...

    Python Cookbook英文版

    5.9 Decorating an Object with Print-Like Methods 5.10 Checking if an Object Has Necessary Attributes 5.11 Making a Fast Copy of an Object 5.12 Adding Methods to a Class at Runtime 5.13 ...

    Making Use of Python (2002).pdf

    Create a Sequence to Store All the Names of the Students 42 Write the Code to Display the Names of the Students 42 Contents v Declare a Dictionary of Student Purchases with the Names of the ...

    Python3.x+QFileDialog 实现界面功能“选择文件夹”、“选择文件”、“选择多个文件”和“保存文件”

    filename = dialog.getOpenFileName(None, "选取文件", "", "All Files (*)")[0] print("所选文件:", filename) app.quit() ``` **选择多个文件:** 当需要让用户一次性选择多个文件时,可以使用`QFileDialog....

    Python将md批量转为docx1

    all_whole_path_files = [] for root, dirs, files in os.walk(file_dir): for file in files: try: if file[-3:] == ".md": file_info = [root+'/', file] all_whole_path_files.append(file_info) except ...

    用python在日志中查找文件路径并删除文件

    例如,假设日志条目中文件路径的标准格式为`/path/to/file.ext`,我们可以创建一个模式来匹配这种格式。 ```python import re def find_file_paths_in_log(log_file): with open(log_file, 'r') as f: content =...

    BatchPdg2Pdf源码python.zip

    print( "Deleting all in " + dir1 ) tfs = os.listdir( dir1 ) if len(tfs) > 0: print( "Warning: there are files in ", dir1, ", will be deleted" ) for tf in tfs: os.remove( os.path.join(dir1, ...

    python学习2.0Apache配置.pdf

    DocumentRoot /path/to/your/django/static/files # 替换为静态文件路径 WSGIScriptAlias / /path/to/your/django/mysite.wsgi # 替换为.wsgi文件路径 <Directory /path/to/your/django/> Order allow,deny ...

    查找程序根目录下的所有文件

    void listAllFiles(File dir) { File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { listAllFiles(file); } else { Log.d("File", "Path: " + ...

    Python对Excel操作详解.doc

    file_path = filedialog.askopenfilename(filetypes=(("Excel Files", "*.xls"), ("All Files", "*.*"))) # 接下来可能需要使用Tcl/Tk的API或其他接口来操作文件 ``` 5. pandas库:现代Python处理Excel的首选库...

    Python实现的根据文件名查找数据文件功能示例

    这两个列表随后被用于`doTheCompare`函数,该函数比较两个列表中的元素,如果在`NameFiles`中的文件名也在`AllFiles`中找到,则使用`shutil.copyfile`将源文件复制到目标目录。 此外,示例还提供了一个简化的文件...

    python使用os模块的os.walk遍历文件夹示例

    if __name__ == ‘__main__’: try: ”’traval and list all files and all dirs”’ for root, dirs, files in os.walk(‘D:’ + os.sep + ‘Python27’): print ‘——————-directory < ‘ + root + ...

    Python3指定路径寻找符合匹配模式文件

    本文实例讲述了Python3指定路径寻找符合匹配模式文件。分享给大家供大家参考。具体实现方法如下: 这里给定一个搜索路径,需要在此目录中找出所有符合匹配模式的文件 ...print(type(all_files('*.

    Python读取一个目录下所有目录和文件的方法

    print('总文件数:', all_file_num) ``` 在这个示例中,我们定义了一个名为`print_path`的递归函数,用于打印指定目录下的所有子目录和文件。函数接受两个参数,`level`表示当前目录的层级,`path`是当前目录的路径...

Global site tag (gtag.js) - Google Analytics