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
Question
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
Cevap
Atakan Au

How to download files keeping directory structure Windows 10?
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:
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:\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

Download the file contents with the "curl" command:
Download the files with the "curl" command and overwrite their contents:
Alternatively, the "Invoke-WebRequest" command can be used in the following formats:
curl https://domain.tld/path/sub_path/file.zip -O C:\dir\sub_dir\file.zipTo 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"


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:
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:

0 comments:
Post a Comment
ⓘ Comment is published after moderation.