Automate file openning on Windows to facilitate research
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:
.pptx (PowerPoint)
.docx (Word)
.html (Web pages)
“Cutoff” Logic (Date Filtering):
If you provide a date (YYYY-MM-DD HH:MM): It will find files modified after that timestamp (useful for resuming recent work).
If you leave it blank: It will find all matching files in the directory tree.
Safety Check:
It lists exactly which files were found.
It pauses to ask you: Open these files? (Y/N) so you don’t accidentally open 50 documents at once.
Zotero Launch:
After handling the documents, it attempts to launch the citation software Zotero.
It checks standard installation paths (Program Files and Program Files (x86)). If not found there, it tries to run zotero.exe directly (assuming it is in your system PATH).
How to Use It:
Place the script in the root folder where your project documents are stored.
Run the script.
Type a cutoff time (e.g., 2025-08-18 14:30) to see only files edited after that time, or press Enter to see everything.
Type Y to confirm and open them.
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
