Pathlib and Python Directory Management

Last Updated :
Discuss
Comments

Question 1

What is the main difference between PurePath and Path classes in the pathlib module?

  • A

    PurePath is used on Windows only, while Path is used on UNIX systems only

  • B

    PurePath handles I/O operations, while Path is used for path computation only

  • C

    PurePath performs only path computations without I/O, while Path supports both computation and actual file operations

  • D

    Both are exactly the same

Question 2

Which method is used to list all .py files inside a directory and its subdirectories?

  • A

    Path.glob('*.py')

  • B

    Path.listdir('*.py')

  • C

    Path.rglob('*.py')

  • D

    Path.walk('*.py')

Question 3

What does the Path.cwd() method return?

  • A

    The path of the home directory

  • B

    The path of the root directory

  • C

    The path where Python is installed

  • D

    The current working directory path

Question 4

What is the main difference between os.mkdir() and os.makedirs()?

  • A

    os.mkdir() creates files, os.makedirs() creates directories

  • B

    os.makedirs() can create nested directories, os.mkdir() cannot

  • C

    os.mkdir() deletes directories, os.makedirs() renames them

  • D

    Both functions do exactly the same thing

Question 5

Which method would you use to list all the files and folders inside the current working directory (non-recursively)?

  • A

    os.walk()

  • B

    os.listdir()

  • C

    os.scan()

  • D

    os.traverse()

Question 6

You want to delete a non-empty folder named old_data. What function should you use?

  • A

    os.rmdir("old_data")

  • B

    os.remove("old_data")

  • C

    shutil.rmtree("old_data")

  • D

    os.delete("old_data")

Tags:

There are 6 questions to complete.

Take a part in the ongoing discussion