Automate file openning on Windows to facilitate research

automation
script
Published

August 20, 2025

Photo by fabio on Unsplash

Photo by fabio on Unsplash

Sometimes, we need to open multiple files at once to start our work. Here is a simple script to automate this process.

This Windows Batch below allows you to batch-open specific documents (Word, PowerPoint, HTML) found in the current folder (and subfolders) along with the Zotero reference manager. It gives you the option to open all matching files or only those modified after a specific date and time.

Key Functionality

File Type Filtering: It searches recursively for files with these extensions:

“Cutoff” Logic (Date Filtering):

Safety Check:

Zotero Launch:

How to Use It:

launcher.bat
@echo off
title Open PPTX/DOCX/HTML (all or edited after cutoff) + Zotero
setlocal EnableExtensions
pushd "%~dp0" || goto :END

REM --- accept optional command-line args ---
set "CUTOFF="
if not "%~1"=="" set "CUTOFF=%~1"
if not "%~2"=="" set "CUTOFF=%CUTOFF% %~2"

if not defined CUTOFF (
  echo.
  echo Enter cutoff in format: YYYY-MM-DD HH:MM   (example: 2025-08-18 14:30)
  echo Or leave blank and press Enter to open ALL files.
  set /p "CUTOFF=Cutoff ^> "
)

set "PSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe"

REM --- PowerShell logic ---
"%PSH%" -NoLogo -NoProfile -ExecutionPolicy Bypass -Command ^
  "$allow=@('.pptx','.docx','.html');" ^
  "if([string]::IsNullOrWhiteSpace($env:CUTOFF)){" ^
  "  Write-Host 'No cutoff provided → selecting ALL files';" ^
  "  $files=Get-ChildItem -Path '.' -Recurse -File | Where-Object { $allow -contains $_.Extension.ToLowerInvariant() } | Sort-Object LastWriteTime" ^
  "} else {" ^
  "  try{ $cut=[datetime]::ParseExact($env:CUTOFF,'yyyy-MM-dd HH:mm',$null) }catch{ Write-Host 'ERROR: Bad datetime format. Use YYYY-MM-DD HH:MM'; exit 2 };" ^
  "  $files=Get-ChildItem -Path '.' -Recurse -File | Where-Object { $allow -contains $_.Extension.ToLowerInvariant() -and $_.LastWriteTime -gt $cut } | Sort-Object LastWriteTime" ^
  "};" ^
  "if(-not $files){ Write-Host 'No matching PPTX/DOCX/HTML files.'; exit 1 };" ^
  "Write-Host ('Found {0} file(s):' -f $files.Count);" ^
  "$files | ForEach-Object { Write-Host ('  {0}  (edited {1:g})' -f $_.FullName,$_.LastWriteTime) };" ^
  "$ans = Read-Host 'Open these files? (Y/N)';" ^
  "if($ans -match '^(y|Y)$'){ $files | ForEach-Object { Start-Process -FilePath $_.FullName } } else { Write-Host 'Cancelled by user.'; exit 0 };" ^
  "if(Test-Path 'C:\Program Files\Zotero\zotero.exe'){ Start-Process 'C:\Program Files\Zotero\zotero.exe' }" ^
  "elseif(Test-Path 'C:\Program Files (x86)\Zotero\zotero.exe'){ Start-Process 'C:\Program Files (x86)\Zotero\zotero.exe' }" ^
  "else{ Start-Process 'zotero.exe' }"

:END
echo.
echo Done. Press any key to exit...
pause >nul
popd
endlocal
Back to top