benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a5f59044-9380-5464-be46-1e4161947d7a

Problem

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

complete prompt

import os
import errno
import shutil

def task_func(filename, dest_dir):
    """
    Copy a file to a specified destination directory and clear its contents.
    This function takes in the path to a file and a destination directory path.
    It copies the file to the destination directory. Once the file is copied,
    the function will erase the content of the original file, leaving it empty.

    Parameters:
    - filename (str): The path to the file to be copied and erased. This must be an
                      absolute path or relative to the current working directory.
    - dest_dir (str): The path to the destination directory where the file will be copied.
                      This must be an absolute path or relative to the current working directory.
                      The directory will be created if it does not exist.

    Returns:
    - str: The absolute path to the copied file within the destination directory.

    Requirements:
    - os
    - errno
    - shutil
    
    Raises:
    - OSError: If the destination directory cannot be created and does not exist, or if the file
               cannot be copied for reasons other than a pre-existing directory.

    Examples:
    >>> task_func('/path/to/original/test.txt', '/path/to/destination')
    '/path/to/destination/test.txt'

    Notes:
    - If the destination directory already contains a file with the same name, the function
      will overwrite that file without warning.
    - The original file will not be deleted from the filesystem, only its content will be cleared.
    """

instruct prompt

Copy a file to a specified destination directory and clear its contents. This function takes in the path to a file and a destination directory path. It copies the file to the destination directory. Once the file is copied, the function will erase the content of the original file, leaving it empty.
Note that: Notes: If the destination directory already contains a file with the same name, the function will overwrite that file without warning. The original file will not be deleted from the filesystem, only its content will be cleared.
The function should raise the exception for: OSError: If the destination directory cannot be created and does not exist, or if the file cannot be copied for reasons other than a pre-existing directory.
The function should output with:
    str: The absolute path to the copied file within the destination directory.
You should write self-contained code starting with:

Code

import os
import errno
import shutil
def task_func(filename, dest_dir):

code prompt

Code

import os
import errno
import shutil
def task_func(filename, dest_dir):

entry point

task_func

libs

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