About 24,000,000 results
Open links in new tab
  1. python - Find the current directory and file's directory - Stack …

    How do I determine: the current directory (where I was in the shell when I ran the Python script), and where the Python file I am executing is?

  2. python - How do I list all files of a directory? - Stack Overflow

    Jul 9, 2010 · How can I list all files of a directory in Python and add them to a list?

  3. How do I change the working directory in Python? - Stack Overflow

    cd is the shell command to change the working directory. What is the equivalent in Python?

  4. 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 …

  5. python - How do I remove/delete/replace a folder that is not …

    Essentially it's using Python's subprocess module to run the bash script $ rm -rf '/path/to/your/dir as if you were using the terminal to accomplish the same task. It's not fully Python, but it gets it …

  6. How should I write a Windows path in a Python string literal?

    Apr 9, 2023 · How should I write a Windows path in a Python string literal? Asked 15 years, 6 months ago Modified 1 year, 10 months ago Viewed 809k times

  7. 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 …

  8. python - How do I get the full path of the current file's directory ...

    2814 The special variable __file__ contains the path to the current file. From that we can get the directory using either pathlib or the os.path module. Python 3 For the directory of the script …

  9. How do I find the location of my Python site-packages directory?

    python -m site --user-site If this points to a non-existing directory check the exit status of Python and see python -m site --help for explanations. Hint: Running pip list --user or pip freeze --user …

  10. How do I move a file in Python? - Stack Overflow

    Jan 13, 2012 · Go here for full write up. In a nutshell, Python's shutil.move will raise an exception (but gnu-coreutils mv will not) when your destination is a directory and the directory already …