Showing posts with label PowerShell. Show all posts

Batch download files keeping directory structure

You can bulk download all listed directories and files with PowerShell on Windows. Jump to online tool

How to batch download files and folders keeping directory structure?

You must do a two-step process to preserve the directory structure and filenames.
1

Create specific directory and file with PowerShell's "New-Item" command. Then save the file on the internet to your local disk with the "curl" command.

1
Download files keeping directory structure

How to download files keeping directory structure Windows 10?

Open PowerShell

Hit the "Start" icon.
Then choose "All Apps" Scroll down, press "Windows PowerShell" folder to open it. Click "Windows PowerShell" to run it.
Open PowerShell

Use PowerShell's commands

Create the directory on your disk
Create the necessary directory and subdirectories on your local disk with PowerShell's "New-Item" command:
New-Item -ItemType File -Force -Path C:\dir\sub_dir\file.zip

For example, you will download these two files:
https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/js/bootstrap.min.js
https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/css/bootstrap.min.css


Let's create these directories and files:
C:\local\htdocs\asset\bootstrap\5.2.3\js\bootstrap.min.js
C:\local\htdocs\asset\bootstrap\5.2.3\css\bootstrap.min.css


Run these commands:
New-Item -ItemType File -Force -Path C:\local\htdocs\asset\bootstrap\5.2.3\js\bootstrap.min.js
New-Item -ItemType File -Force -Path C:\local\htdocs\asset\bootstrap\5.2.3\css\bootstrap.min.css
Create the necessary directory and subdirectories on your local disk with PowerShell New-Item command

Download the file contents with the "curl" command:
Download the files with the "curl" command and overwrite their contents:
curl https://domain.tld/path/sub_path/file.zip -O C:\dir\sub_dir\file.zip
To save the two files in the example above to your disk, keeping the same directory structure, run these commands:
curl https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/js/bootstrap.min.js -O C:\local\htdocs\asset\bootstrap\5.2.3\js\bootstrap.min.js
curl https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/css/bootstrap.min.css -O C:\local\htdocs\asset\bootstrap\5.2.3\css\bootstrap.min.css


Alternatively, the "Invoke-WebRequest" command can be used in the following formats:
Invoke-WebRequest -Uri "Source-Uri" -OutFile "Save-File"
Download the files with curl command

Download the files with curl command


Automatically create the PowerShell script


Paste your url list. Set parameters. Generate your PowerShell. Copy the script. Paste it into the PowerShell command line. That is all.

Download url list:


Options

Combine all files in one zip file and download. It only works in modern and up to date browser. The total file size should not exceed ~5 MB.






PowerShell script:


Automatically create the PowerShell script onlie tool
Share:

Subscribe to: Posts (Atom)