About 2,560,000 results
Open links in new tab
  1. How can I delete a file or folder in Python? - Stack Overflow

    How do I delete a file or folder in Python? For Python 3, to remove the file and directory individually, use the unlink and rmdir Path object methods respectively:

  2. Most pythonic way to delete a file which may not exist

    Jun 1, 2012 · os.remove(filename) If filename is a pathlib.Path object instead of a string, we can call its .unlink() method instead of using os.remove(). In my experience, Path objects are more …

  3. How to permanently delete a file in python 3 and higher?

    Jul 21, 2019 · I want to permanently delete a file i have created with my python code. I know the os.remove() etc but can't find anything specific to delete a file permanently.(Don't want to fill …

  4. How do I get the filename without the extension from a path in …

    Use os.path.basename and removesuffix to remove multiple extensions and directory name, and return just the file basename. Useful, for example, to remove extension .tar.gz from …

  5. How to delete specific strings from a file? - Stack Overflow

    I have a data file (unstructured, messy file) from which I have to scrub specific list of strings (delete strings). Here is what I am doing but with no result: infile = r"messy_data_file.txt&q...

  6. python - Remove all files in a directory - Stack Overflow

    7 Because the * is a shell construct. Python is literally looking for a file named "*" in the directory /home/me/test. Use listdir to get a list of the files first and then call remove on each one.

  7. How to delete a file by extension in Python? - Stack Overflow

    Sep 29, 2015 · For this operation you need to append the file name on to the file path so the command knows what folder you are looking into. You can do this correctly and in a portable …

  8. How to delete a specific line in a text file using Python?

    Let's say I have a text file full of nicknames. How can I delete a specific nickname from this file, using Python?

  9. python - Delete multiple files matching a pattern - Stack Overflow

    os.remove(os.path.join(root, file)) You can safely remove subdirectories on the fly from dirs, which contains the list of the subdirectories to visit at each node.

  10. Deleting files which start with a name Python - Stack Overflow

    Jan 6, 2010 · If you really want to use Python, you can just use a combination of os.listdir (), which returns a listing of all the files in a certain directory, and os.remove ().