Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:48:24+00:00 2026-06-09T15:48:24+00:00

I can download a single file from the web using: $wc = New-Object System.Net.WebClient

  • 0

I can download a single file from the web using:

$wc = New-Object System.Net.WebClient
$wc.DownloadFile("http://blah/root/somefile.ext", "C:\Downloads\www\blah\root\somefile.ext")

But how do I download all the files, including subfolders? Something like the following would be nice…

$wc.DownloadFile("http://blah/root/", "C:\Downloads\www\blah\root\")

The root folder itself appears as a directory listing in IE, you know, like:

[To Parent Directory]
                01 July 2012    09:00       1234 somefile.ext
                01 July 2012    09:01       1234 someotherfile.ext

As a bonus, how would I just downloading the files in the root folder, ignoring subfolders?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:48:25+00:00Added an answer on June 9, 2026 at 3:48 pm

    Here’s what I came up with based on Andy’s suggestion (with plenty of help from Google, of course):

    ####################################################################################################
    # This function copies a folder (and optionally, its subfolders)
    #
    # When copying subfolders it calls itself recursively
    #
    # Requires WebClient object $webClient defined, e.g. $webClient = New-Object System.Net.WebClient
    #
    # Parameters:
    #   $source      - The url of folder to copy, with trailing /, e.g. http://website/folder/structure/
    #   $destination - The folder to copy $source to, with trailing \ e.g. D:\CopyOfStructure\
    #   $recursive   - True if subfolders of $source are also to be copied or False to ignore subfolders
    #   Return       - None
    ####################################################################################################
    Function Copy-Folder([string]$source, [string]$destination, [bool]$recursive) {
        if (!$(Test-Path($destination))) {
            New-Item $destination -type directory -Force
        }
    
        # Get the file list from the web page
        $webString = $webClient.DownloadString($source)
        $lines = [Regex]::Split($webString, "<br>")
        # Parse each line, looking for files and folders
        foreach ($line in $lines) {
            if ($line.ToUpper().Contains("HREF")) {
                # File or Folder
                if (!$line.ToUpper().Contains("[TO PARENT DIRECTORY]")) {
                    # Not Parent Folder entry
                    $items =[Regex]::Split($line, """")
                    $items = [Regex]::Split($items[2], "(>|<)")
                    $item = $items[2]
                    if ($line.ToLower().Contains("&lt;dir&gt")) {
                        # Folder
                        if ($recursive) {
                            # Subfolder copy required
                            Copy-Folder "$source$item/" "$destination$item/" $recursive
                        } else {
                            # Subfolder copy not required
                        }
                    } else {
                        # File
                        $webClient.DownloadFile("$source$item", "$destination$item")
                    }
                }
            }
        }
    }
    

    No guarantees of course, but it worked for the site I was interested in

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can download a file from S3 using either of the following methods. s3cmd
How can I download single file from an SVN repository? For example: svn co
I want to download a single .mp3 file from my site but when using
I'm using C++ without .NET on Win32, how can I download an image over
Is there a way to programmatically download a single file from a remote Mercurial
Can anyone tell me how I can download a picture from a URL and
With this code I can download the file but I should know the file
Can anybody help me, from where I can download LevelDB for Java-Windows because I
I need help with NinePatchDrawable: My app can download themes from the network. Almost
We're writing a flash application that can download a MP3 file, convert it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.