3 ms·
count_the_files_in_this_folder.bat ``` @echo off setlocal set "PROMPT=%~n0" setx OPENAI_API_KEY "sk-proj-x" >nul 2>&1 powershell -NoProfile -Command ^ "$
by cheevly 7mo ago
count_the_files_in_this_folder.bat
```
@echo off
setlocal
set "PROMPT=%~n0"
setx OPENAI_API_KEY "sk-proj-x" >nul 2>&1
powershell -NoProfile -Command ^
"$env:OPENAI_API_KEY='%OPENAI_API_KEY%';" ^
"$files = Get-ChildItem -File | ForEach-Object { $_.Name };" ^
"$filesList = $files -join ', ';" ^
"$systemPrompt = 'You are only allowed to respond with executable PowerShell commands. The folder contains these files: ' + $filesList;" ^
"$userPrompt = '%PROMPT%';" ^
"$body = @{ model='gpt-5.4'; messages=@(@{role='system'; content=$systemPrompt}, @{role='user'; content=$userPrompt}) } | ConvertTo-Json -Depth 5;" ^
"$response = Invoke-RestMethod -Uri 'https://api.openai.com/v1/chat/completions https://api.openai.com/v1/chat/completions' -Method Post -Headers @{ Authorization = 'Bearer ' + $env:OPENAI_API_KEY; 'Content-Type' = 'application/json' } -Body $body;" ^
"$psCommand = $response.choices[0].message.content;" ^
"Write-Host '---AI OUTPUT---';" ^
"Write-Host $psCommand;" ^
"Invoke-Expression $psCommand"
pause
```