# Path to the folder containing .swf files $folderPath = "D:\FlashSWF\Simple_loops_and_scenery" # Path to the flash player executable (e.g., Ruffle, Flash Player Projector) # Ensure this path is correct and the executable can be run. $playerPath = "D:\FlashSWF\ruffle.exe" # --- Script Start --- Write-Host "Searching for .swf files in: '$folderPath'" # Get all .swf files in the specified folder # Get-ChildItem returns FileInfo objects, which contain FullName, Name, etc. $swfFiles = Get-ChildItem -Path $folderPath -Filter "*.swf" -ErrorAction SilentlyContinue # Check if any .swf files were found if ($swfFiles.Count -eq 0) { Write-Host "Error: No .swf files found in the folder '$folderPath'." Write-Host "Please ensure the folder path is correct and contains .swf files." exit } Write-Host "Found $($swfFiles.Count) .swf files." Write-Host "Starting continuous playback in randomized order. Press Ctrl+C to stop." # Infinite loop to continuously play randomized playlists while ($true) { Write-Host "`n--- Shuffling playlist for a new cycle ---" # Randomize the order of the SWF files # Get-Random with -Count $swfFiles.Count ensures all files are returned in a random order $randomizedPlaylist = $swfFiles | Get-Random -Count $swfFiles.Count # Loop through each file in the newly randomized playlist foreach ($file in $randomizedPlaylist) { Write-Host "Playing: $($file.Name) (Path: $($file.FullName))" # Start the flash player process # -PassThru captures the process object, allowing us to manage it specifically # The argument list needs the full path enclosed in double quotes in case of spaces try { $process = Start-Process -FilePath $playerPath -ArgumentList "`"$($file.FullName)`"" -PassThru -ErrorAction Stop } catch { Write-Host "Error starting player for $($file.Name): $($_.Exception.Message)" Write-Host "Please ensure '$playerPath' is a valid executable." # Attempt to continue with the next file if player fails to start continue } # Wait for 10 seconds before closing the current player Start-Sleep -Seconds 25 # Attempt to close the specific flash player process that was just opened if ($process -and -not $process.HasExited) { Write-Host "Stopping process (ID: $($process.Id)) for $($file.Name)..." try { Stop-Process -Id $process.Id -Force -ErrorAction Stop } catch { Write-Host "Warning: Could not stop process (ID: $($process.Id)). It might have already closed or access was denied." } } else { Write-Host "Process for $($file.Name) already exited or was not found running." } # Optional: Add a small delay between files if desired # Start-Sleep -Seconds 1 } Write-Host "`n--- Finished playing all files in this cycle. Preparing for next cycle. ---" # Optional: Add a short pause before starting the next full cycle of randomized files Start-Sleep -Seconds 5 } # To convert this script to an executable (.exe), you can use PS2EXE: # Invoke-PS2EXE -InputFile "your_script_name.ps1" -OutputFile "your_script_name.exe" # Invoke-PS2EXE -InputFile "C:\Users\User\Desktop\Flashes_array.txt" -Outputfile "C:\Users\User\Desktop\Flashes_array.exe" # To stop the script while it's running in PowerShell, press Ctrl + C.