benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf e4451104-7ee1-58da-a34f-0b4e7437cea7

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import os
import re

def task_func(pattern, log_dir='/var/log/'):
    """
    Find the latest log file in a specified directory that matches a given regex pattern.

    This function searches through all files in the specified directory, filters them based on the provided regex pattern, 
    and returns the path to the most recent log file based on modification time. If no files match the pattern or the directory 
    is empty, the function returns None.

    Parameters:
        pattern (str): The regex pattern to match the names of the log files.
        log_dir (str, optional): The directory to search for log files. Defaults to '/var/log/'.

    Returns:
        str or None: The path to the most recent log file that matches the pattern, or None if no matching files are found.

    Requirements:
    - os
    - re

    Example:
    >>> task_func(r'^access.log.[0-9]+$', '/var/log/')
    '/var/log/access.log.1234'
    """

instruct prompt

Find the latest log file in a specified directory that matches a given regex pattern. This function searches through all files in the specified directory, filters them based on the provided regex pattern, and returns the path to the most recent log file based on modification time. If no files match the pattern or the directory is empty, the function returns None.
The function should output with:
    str or None: The path to the most recent log file that matches the pattern, or None if no matching files are found.
You should write self-contained code starting with:

Code

import os
import re
def task_func(pattern, log_dir='/var/log/'):

code prompt

Code

import os
import re
def task_func(pattern, log_dir='/var/log/'):

entry point

task_func

libs

  • re
  • os

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import