# PowerShell script to read links from readme.md and download files # Usage: .\download_links.ps1 # Check if readme.md exists if (-not (Test-Path "readme.md")) { Write-Host "Error: readme.md file not found!" -ForegroundColor Red exit 1 } # Read file content $content = Get-Content "readme.md" -Raw # Extract all https links Write-Host "Extracting links from readme.md..." -ForegroundColor Yellow $links = [regex]::Matches($content, 'https://[^\s]*') | ForEach-Object { $_.Value } # Check if links were found if ($links.Count -eq 0) { Write-Host "Error: No links found in readme.md!" -ForegroundColor Red exit 1 } Write-Host "Found links:" -ForegroundColor Green $links | ForEach-Object { Write-Host $_ } Write-Host "" # Download each file $count = 0 $index = 1 foreach ($url in $links) { # Extract filename from URL and add index prefix to avoid conflicts $baseFilename = [System.IO.Path]::GetFileName($url) $filename = "$index-$baseFilename" Write-Host "Downloading: $filename" -ForegroundColor Cyan # Use Invoke-WebRequest to download file try { Invoke-WebRequest -Uri $url -OutFile $filename Write-Host "✓ Download successful: $filename" -ForegroundColor Green $count++ } catch { Write-Host "✗ Download failed: $filename" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } $index++ } Write-Host "" Write-Host "Download completed! Successfully downloaded $count files." -ForegroundColor Green