回复 2# flashercs
多谢大佬, powershell不是支持并行处理吗?
我用gpt生成了如下代码, 能执行成功, 但是没有进度条, 发现gpt还是不够智能, N多轮才能搞成- # 定义文件的URL和保存路径
- $urls = @(
- "https://dldir1v6.qq.com/weixin/Windows/WeChatSetup.exe",
- "https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.15_240902_x64_01.exe",
- "https://dldir1.qq.com/qqfile/qq/TIM3.5.0/TIM3.5.0.22143.exe"
- )
-
- # 获取桌面路径
- $desktop = [System.Environment]::GetFolderPath('Desktop')
-
- # 创建一个存储作业的数组
- $jobs = @()
-
- # 启动并行下载作业
- foreach ($url in $urls) {
- $fileName = Split-Path $url -Leaf
- $outputPath = Join-Path $desktop $fileName
-
- $jobs += Start-Job -ScriptBlock {
- param($downloadUrl, $savePath)
- Invoke-WebRequest -Uri $downloadUrl -OutFile $savePath
- } -ArgumentList $url, $outputPath
- }
-
- # 等待所有作业完成
- $jobs | ForEach-Object {
- Wait-Job $_
- Remove-Job $_
- }
-
- Write-Host "所有文件下载完成!"
复制代码
|