#delete all mp4 files in the dir import os for f in os.listdir(): if f.endswith(".mp4"): os.remove(f) print("Tutti i file mp4 in questa cartella sono stati cancellati.")
Making things a little more complex
If you want to ask the user if he really want to remove them, you can use this code, that also tells you which are the files in the folder, what is the folder where the files are.
#delete all mp4 files in the dir import os import glob mp4 = glob.glob("*.mp4") if mp4 != []: print(mp4) print("Do you want to remove all the mp4 in " + os.getcwd() + " ?") ask = input("(y/n)>: ") if ask == "y": for f in os.listdir(): if f.endswith(".mp4"): os.remove(f) print("All files have been deleted") else: print("Ok, no file has been deleted") print("This code was gently offered by https://pythonprogramming.altervista.org") else: print("There is nothing to delete in this folder")
Another thing you could do, is to ask the type of file you want to delete.
This is the .bat file
You can make the program start with a batch file like this where you can use py or python or python3 to make python start, followed by the name of the python file (in this case is delete_mp4.py, remember to put the correct name of the script that you saved in the dir). You can put this file in another dir, adding the path before the file (py h:\pythonscripts\delete_mp4.py for example).
py delete_mp4.py pause
Now, you can click on this or the other one.
Video
Twitter: @pythonprogrammi - python_pygame