Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Python: Finding meet the conditions specified in the file directory     - Linux environment variable settings and save places (Linux)

- Linux System Tutorial: Fix ImportError: No module named wxversion error (Linux)

- How to properly set up a Linux swap partition (Linux)

- Zypper command for SUSE Linux package management (Linux)

- Use Observium to monitor your network and servers (Server)

- Handle large data problems Bit-map method (Programming)

- ORA-12537: TNS: connection closed error process (Database)

- Lucene Getting Started Tutorial (Server)

- Linux resource restriction level summary (Linux)

- MYSQL root password for the database user passwords are weak attack analysis (Linux)

- To create a secure network firewall with iptables Under Linux (Linux)

- How to remove the files inside the privacy of data on Linux (Linux)

- swap space is insufficient cause OOM kill MySQL Case (Database)

- C # get the current screenshot (Programming)

- Linux alpine use the command line to access Gmail (Linux)

- Xmanager Remote Desktop connection CentOS (Linux)

- Flask installation environment (Linux)

- History of the most complex validation e-mail address regular expression (Linux)

- Linux System Getting Started Learning: compile and install ixgbe driver in Ubuntu or Debian (Linux)

- PHP loop reference caused strange problems (Programming)

 
         
  Python: Finding meet the conditions specified in the file directory
     
  Add Date : 2018-11-21      
         
       
         
  1. Python file names containing keywords to find files in the specified directory and its subdirectories

Source

# Search.py
import os
import sys

def search (path, word):
    for filename in os.listdir (path):
        fp = os.path.join (path, filename)
        if os.path.isfile (fp) and word in filename:
            print fp
        elif os.path.isdir (fp):
            search (fp, word)

search (sys.argv [1], sys.argv [2])

use

python search.py directory_path keyword

2. Find the file contents in the development directory and its subdirectories contain the keyword file

Source

# Search.py
import os
import sys

def search (path, word):
    for filename in os.listdir (path):
        fp = os.path.join (path, filename)
        if os.path.isfile (fp):
            with open (fp) as f:
                for line in f:
                    if word in line:
                        print fp
                        break
        elif os.path.isdir (fp):
            search (fp, word)

search (sys.argv [1], sys.argv [2])

use

python search.py directory_path keyword
     
         
       
         
  More:      
 
- Puppet installation and testing (Server)
- How to install MySQL on Linux Dock (Database)
- Oracle Data Pump Example (Database)
- Using Python multithreaded mistakes summary (Programming)
- Ambari and Hadoop configuration, management and monitoring of the project Getting (Server)
- Encounter ORA-00600: internal error code, arguments: [4194] ORA-1552 (Database)
- Stucts2 values on the page and how the attribute values corresponding to the Action (Programming)
- Network Security Basics Linux command (Linux)
- Linux System Getting Started Learning: The Linux anacron command (Linux)
- Character Encoding notes: ASCII, Unicode and UTF-8 (Linux)
- Java, extends and implements Usage (Programming)
- The difference between free command displays the buffers and cache (Linux)
- Analysis of C ++ exception mechanism (Programming)
- Summarize small problems encountered in the use Lua (Programming)
- MySQL 5.7.9 source compiler installation instructions (Database)
- Linux installation and error under codeblocks exclude [Ubuntu 10.04] (Linux)
- Ubuntu GCC, G ++ and fortran Version Switch (Linux)
- Docker data container protection the pros and cons (Server)
- a virtual machine created migrated to host RHEL6.4 on Ubuntu 14.04 (Linux)
- OpenStack Folsom create an instance of the failure of the Quota Fixed_IP articles (Server)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.