Personal Project Portfolio
python
bash
powershell
1# Script to go through a given directory recusively and remove files based on file extension
2
3import os
4
5"""
6Directory path should be formatted as follows:
7 '<disk>:/path/to/file
8 Windows example: C:/Users/test/testUser/Downloads
9 MacOS example: /Volume/folderName
10"""
11
12directoryToUse = <insert path to top folder here>
13
14for subdir, dirs, files in os.walk(directoryToUse):
15 for file in files:
16 if file.endswith("<add file extension in quotes"):
17 #os.remove or os.unlink both work here as their functionality is identical, remove comes from windows, unlink from UNIX
18 os.remove(os.path.join(directoryToUse, subdir, file))