benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 21b08905-fa35-5ce9-920c-469c9a872c44

Problem

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

complete prompt

import os
import re
import shutil


def task_func(source_directory: str, target_directory: str, pattern: str = r"\d{4}") -> int:
    """
    Moves files matching a specific regex pattern from a source directory to a target directory.

    Parameters:
    - source_directory (str): Path of the source directory from which files will be moved.
    - target_directory (str): Path of the target directory to which files will be moved.
    - pattern (str): Regex pattern to match filenames.
                     Defaults to r'\\d{4}' to match filenames containing four contiguous digits.

    Returns:
    - int: The number of files successfully moved.

    Requirements:
    - os
    - re
    - shutil

    Note:
    - If source_directory does not exist or is not a directory, this function returns 0.
    - If target_directory does not exist, this function will create it.

    Examples:
    >>> os.listdir('/path/to/source')
    ['1000.txt', '1001.txt', '1002.txt', 'not_a_match.txt']
    >>> task_func('/path/to/source', '/path/to/target')
    3
    """

instruct prompt

Moves files matching a specific regex pattern from a source directory to a target directory.
Note that: If source_directory does not exist or is not a directory, this function returns 0. If target_directory does not exist, this function will create it.
The function should output with:
    int: The number of files successfully moved.
You should write self-contained code starting with:

Code

import os
import re
import shutil
def task_func(source_directory: str, target_directory: str, pattern: str = r"\d{4}") -> int:

code prompt

Code

import os
import re
import shutil
def task_func(source_directory: str, target_directory: str, pattern: str = r"\d{4}") -> int:

entry point

task_func

libs

  • shutil
  • 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