Error message

  • Deprecated function: Return type of DatabaseStatementBase::execute($args = [], $options = []) should either be compatible with PDOStatement::execute(?array $params = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2244 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in drupal_random_bytes() (line 2268 of /home2/psicolog/public_html/feliponcho/includes/bootstrap.inc).
  • Deprecated function: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in url() (line 2349 of /home2/psicolog/public_html/feliponcho/includes/common.inc).
  • Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in url_is_external() (line 2393 of /home2/psicolog/public_html/feliponcho/includes/common.inc).
  • Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in url_is_external() (line 2395 of /home2/psicolog/public_html/feliponcho/includes/common.inc).
  • Deprecated function: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in url() (line 2311 of /home2/psicolog/public_html/feliponcho/includes/common.inc).

Phyton script for looking files with specific text pattern, in a directory tree.

'''
Hi, This is the minimized version of some more
complicated script I wrote for some project.
What we basically do here is look for some files (with the same name)
with specific text pattern in it. All files with this
"magic" pattern will be opened with notepad.

Created on Feb 14, 2011

@author: feliponcho
'''

import os
import sys

#set some global data here
pattern = "magic pattern"
search_file = "hello.lst"

#define our methods
def parseFile(filePath):
    try: 
        file = open(filePath, 'rb', 1)
    except IOError:
        return ""
    else: 
        file.close() 
        inList = file.readlines()
        magic = "";
        for line in inList:
            if pattern in str(line):
                return filePath
        return magic        
   

def parseFiles(dirList, dirPath, typeList):
    for file in dirList:
        for ext in typeList:
            if file.endswith(ext):
                filePath = dirPath + "\\" + file
                magic = parseFile( filePath )
                if magic != "":
                    openFile( filePath )                    
    
def parseDirectory(dirEntry, typeList):
    parseFiles(dirEntry[2], dirEntry[0], typeList)
    
def openFile(filePath):
   
    notepad = 'c:\\windows\\system32\\notepad.exe'
       
    if os.path.isfile(filePath):
        os.spawnv(os.P_DETACH, notepad, ('notepad.exe',filePath))

#MAIN STARTS HERE!!
#validate parameter
try:
    path = str(sys.argv[1])

except LookupError:
    print( "Invalid argument: supply only the path of the search Folder")
else:
    print("looking for "+search_file+" in "+path)

    #Convert pattern string to list of file extensions
    extList = []
    for ext in pattern.split(";"):
        extList.append(ext.lstrip("*"))
                      
    #Enumerate the entries in the tree
    for directory in os.walk(path):
        parseDirectory(directory, extList)
    
#MAIN ENDS HERE!!