About 11,000,000 results
Open links in new tab
  1. python - How do I remove/delete/replace a folder that is not …

    It's not fully Python, but it gets it done. The reason I included the pathlib.Path example is because in my experience it's very useful when dealing with many paths that change. The extra steps …

  2. How can I delete a file or folder in Python? - Stack Overflow

    60 Deleting a file or folder in Python There are multiple ways to delete a file in Python but the best ways are the following: os.remove() removes a file. os.unlink() removes a file. It is a Unix alias …

  3. pathlib.Path vs. os.path.join in Python - Stack Overflow

    Apr 15, 2021 · 110 pathlib is the more modern way since Python 3.4. The documentation for pathlib says that "For low-level path manipulation on strings, you can also use the os.path …

  4. python - How to close files using the pathlib module? - Stack …

    from pathlib import Path path = Path("file") for line in path.open(): # do thing to line Most of the references I found are using the with keyword for opening files for the convenience of not …

  5. How can I replace (or strip) an extension from a filename in Python?

    Longer Answer: The best way to do this will depend on your version of python and how many extensions you need to handle. That said, I'm surprised nobody has mentioned pathlib's …

  6. How do I check if a directory exists in Python? - Stack Overflow

    133 Python 3.4 introduced the pathlib module into the standard library, which provides an object oriented approach to handle filesystem paths. The is_dir() and exists() methods of a Path …

  7. python - Use pathlib for S3 paths - Stack Overflow

    Explains how to use Python's pathlib library for handling S3 paths effectively.

  8. How to rename a file using Python - Stack Overflow

    Furthermore, the pathlib library is introduced in python 3.4 so sharing the answer here also provides exposure for a solid module to showcase its versatility and usage for more …

  9. python - How to check whether a directory is a sub directory of …

    Sep 28, 2010 · Python 3.4 added the pathlib module which can perform these kind of path operations in a more sophisticated way, optionally without referencing the underlying OS. jme …

  10. python - Platform-independent file paths? - Stack Overflow

    from pathlib import Path libdir = Path(__file__).resolve().with_name('modules') How it works: the __file__ attribute contains the pathname of the file from which the module was loaded. You …