benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 8538208e-a3ff-57d8-853d-8b2681e48759

Problem

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

complete prompt

import os
import glob
import shutil

def task_func(directory, archive_dir='archive'):
    """
    Archive all JSON files in a given directory by moving them to a specified archive directory.

    Parameters:
    directory (str): The directory where the JSON files are located.
    archive_dir (str): The directory to which the JSON files will be archived. Defaults to 'archive'.

    Returns:
    tuple: A tuple containing a boolean value and a list of error messages.
           The boolean is True if all files are successfully moved, and False otherwise.
           The list contains error messages for each file that failed to move.

    Requirements:
    - os
    - glob
    - shutil

    Example:
    >>> import tempfile
    >>> temp_dir = tempfile.mkdtemp()
    >>> files = ['file1.json', 'file2.json', 'file3.json']
    >>> for file in files:
    ...     with open(os.path.join(temp_dir, file), 'w') as f:
    ...         _ = f.write("Dummy content for testing.")
    >>> backup_dir = tempfile.mkdtemp()
    >>> task_func(temp_dir, backup_dir)
    (True, [])
    """

instruct prompt

Archive all JSON files in a given directory by moving them to a specified archive directory.
The function should output with:
    tuple: A tuple containing a boolean value and a list of error messages.
    The boolean is True if all files are successfully moved, and False otherwise.
    The list contains error messages for each file that failed to move.
You should write self-contained code starting with:

Code

import os
import glob
import shutil
def task_func(directory, archive_dir='archive'):

code prompt

Code

import os
import glob
import shutil
def task_func(directory, archive_dir='archive'):

entry point

task_func

libs

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