benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf ed442e32-2337-5979-86d6-ea23a6d86cfb

Problem

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

complete prompt

import os
from pathlib import Path
import glob
import shutil


def task_func(source_directory: str, target_directory: str):
    """
    Moves files with specific extensions from a source directory to a target directory,
    handling naming conflicts by renaming duplicates.

    Parameters:
    - source_directory (str): The absolute or relative path of the source directory.
    - target_directory (str): The absolute or relative path of the target directory.
                              This function will create it if it does not exist.

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

    Raises:
    - FileNotFoundError: If source_directory does not exist.

    Requirements:
    - os
    - pathlib
    - glob
    - shutil

    Notes:
    - This function scans the source directory recursively to find files.
    - Files are filtered by the extensions: ".txt", ".docx", ".xlsx", ".csv".
    - Renaming of files due to naming conflicts follows the pattern '<original_name>-n.<extension>'.

    Examples:
    >>> task_func('./source_folder', './target_folder')
    3
    >>> task_func('./empty_folder', './target_folder')
    0
    """

instruct prompt

Moves files with specific extensions from a source directory to a target directory, handling naming conflicts by renaming duplicates.
Note that: Notes: This function scans the source directory recursively to find files. Files are filtered by the extensions: ".txt", ".docx", ".xlsx", ".csv". Renaming of files due to naming conflicts follows the pattern '<original_name>-n.<extension>'.
The function should raise the exception for: FileNotFoundError: If source_directory does not exist.
The function should output with:
    int: The number of files successfully moved.
You should write self-contained code starting with:

Code

import os
from pathlib import Path
import glob
import shutil
def task_func(source_directory: str, target_directory: str):

code prompt

Code

import os
from pathlib import Path
import glob
import shutil
def task_func(source_directory: str, target_directory: str):

entry point

task_func

libs

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