Skip to content

Instantly share code, notes, and snippets.

@damieng
Created May 27, 2016 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damieng/6b8041a018f78cb459939192b0938842 to your computer and use it in GitHub Desktop.
Save damieng/6b8041a018f78cb459939192b0938842 to your computer and use it in GitHub Desktop.
Bulk download files from a url by specifying a wildcard and numeric range
$sourcePattern = "http://something.com/somepath/somefile*.jpg"
$targetDir = "c:\downloads"
$count = 256
New-Item -Path $targetDir -ItemType Directory -Force
for ($i=1; $i -le $count; $i++) {
$source = $sourcePattern.Replace("*", $i)
$parts = $source.Split('/')
$target = Join-Path $targetDir $parts[$parts.Length - 1]
echo "Downloading $source to $target"
(New-Object System.Net.WebClient).DownloadFileAsync($source, $target)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment