You are on page 1of 1

To search for video files with a specific starting name across the entire computer

system in Windows using Python, you can use the `os` module to traverse the file
system and identify files that match your criteria. Additionally, you can use the
`fnmatch` module to filter files based on their names.

Here's an example script that searches for video files starting with a given name
(adjust `'your_video_file_name'` accordingly) and having either ".mp4" or ".mkv"
extensions:

```python
import os
import fnmatch

def find_video_files(start_folder, file_name_start):


video_files = []

# Walk through the file system starting from the specified folder
for root, dirs, files in os.walk(start_folder):
for filename in fnmatch.filter(files, file_name_start + '*'):
# Check if the file has a video extension
if filename.lower().endswith(('.mp4', '.mkv')):
video_files.append(os.path.join(root, filename))

return video_files

# Specify the starting folder for the search


start_folder = 'C:\\' # You can change this to the desired starting location

# Specify the starting name of the video file


file_name_start = 'your_video_file_name' # Change this to the desired starting
name

# Search for video files


result = find_video_files(start_folder, file_name_start)

# Print the result


if result:
print("Found video files:")
for video_file in result:
print(video_file)
else:
print("No matching video files found.")
```

Replace `'C:\\'` with the appropriate starting folder for your search. This script
will print the paths of video files matching your criteria. Keep in mind that
searching the entire computer system may take some time, depending on the size of
your filesystem.

You might also like