Code Snippet: Houdini pythonModule common functions
- Ellie Ansell
 - Nov 15, 2020
 - 1 min read
 
Hou.phm() functions for simple tasks, such as returning all files matching a regex from a path. This was used for a lookdev OTL, to grab all HDRIs on shows in given folders.
import os
import re
import sys
import imp
'''
Author: Ellie Ansell
Date edited: 09/04/20
Desc: Simple functions to parse data.
'''
def buildMenuStringList(names):
    """ Duplicates each element in a list of strings.
            For example, ["walk", "run"] becomes ["walk", "walk", "run", "run"]
    """
    return [name for pair in zip(names, names) for name in pair]
def findFiles(path="", re_pattern=".*"):
    """Get a list of the files from a directory matching a given regex.
    """
    if not os.path.exists(path):
            return [""]
    files = []
    for root, ds, fs in os.walk(path):
            for f in fs:
                    if re.match(re_pattern, f) and not f.startswith("."):
                            files.append(f)
    return files or [""]
def findDirs(path="", re_pattern=".*"):
    """Get a list of the files from a directory matching a given regex.
    """
    if not os.path.exists(path):
            return [""]
    files = []
    for f in os.listdir(path):
            if re.match(re_pattern, f) and not f.startswith("."):
                    files.append(f)
    return files or [""]







.jpeg)



Comments