How to run python script on every file in a specific folder (PC)

UPDATE: SOLVED
Hi all, I recently got into blender automation, and I was wondering if there was an easy way to run a script on every blender file within a certain folder.
I read that running one script on one file is done with the command:
blender -b yourfile.blend -P yourscript.py

But this will only run it on one file at a time, is it possible to make blender loop and entire folder?
It’s just that writing a command for each file separately doesn’t seem like the best way to do it.

Is this possible? Thanks!

I came up with a solution! So I’m trying to bake Ambient Occlusion maps for almost 200 blend files in a folder: I made this script in Blender, it basically unwraps and bakes the currently loaded model:

import bpy

scene = bpy.context.scene
selected = bpy.context.selected_objects
object = bpy.ops.object

for obj in selected:
scene.objects.active = obj

object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.lightmap_pack(PREF_CONTEXT='SEL_FACES', PREF_PACK_IN_ONE=True, PREF_NEW_UVLAYER=False, PREF_APPLY_IMAGE=False, PREF_IMG_PX_SIZE=2048, PREF_BOX_DIV=48, PREF_MARGIN_DIV=0.1)
bpy.context.scene.world.light_settings.distance = 500
bpy.context.scene.world.light_settings.samples = 30
bpy.context.scene.world.light_settings.sample_method = 'CONSTANT_QMC'
bpy.context.scene.world.light_settings.use_falloff = True
bpy.context.scene.world.light_settings.falloff_strength = 1

bpy.context.scene.render.use_bake_normalize = True
bpy.context.scene.render.bake_type = 'AO'
bpy.context.scene.render.filepath = "C:\\"
thisFileName = bpy.path.basename(bpy.context.blend_data.filepath)
image = bpy.data.images.new(thisFileName, alpha=False, width=2048, height=2048)
image.colorspace_settings.name = 'sRGB'
image.file_format = "PNG"
image.filepath_raw = "//AOMaps/"+thisFileName+".png"
for area in bpy.context.screen.areas :
    if area.type == 'IMAGE_EDITOR' :
        area.spaces.active.image = image
bpy.ops.object.bake_image()
image.save()

bpy.ops.wm.save_mainfile()

But this can only do one file at a time, and I wanted to be able to do this from command prompt. So I added blender to my PATH in Windows (so I can call blender without cd-ing into the install folder)
I needed to make a .bat file that will loop all of the .blend files in a folder; but instead I ended up doing this:
I ran this line of code in command prompt:

(for /f “delims=” %%f in (‘dir /s /b *.blend’) do @echo blender -b “%%f” -P “C:\Users\The Rampant\Desktop\GameReadyTerrains\GameReadyTerrains\LightmapUnwrap.py”) > “C:\Users\The Rampant\Desktop\BlendBake.txt”

dir /s /b *.blend prints the path of every .blend file in the current folder

blender -b “%%f” -P “C:\Users\The Rampant\Desktop\GameReadyTerrains\GameReadyTerrains\LightmapUnwrap.py” This text is all appended to the path of the .blend file. When it is actually ran, it opens blender in the background, loads a file (in this case, “%%f”), and runs whatever python script you specify (in this case “LightmapUnwrap.py”)

" > “C:\Users\The Rampant\Desktop\BlendBake.txt” " this pushes the entire output of the command into a .txt file called ‘BlendBake.txt’. This is useful because if I just save the .txt file as a .bat file, I’ll be able to run it, telling blender to bake the occlusion map for every .blend file that is mentioned in the .txt file.

So that’s how I did it! These aren’t the clearest instructions because it wasn’t the clearest process haha. If you have any questions please reply!