Help with multi-file downloader
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help with multi-file downloader

  1. #1
    Join Date
    Jan 2010
    Posts
    14

    Help with multi-file downloader

    I want to create a program that can go into a parent directory, travel to each folder in the directory and then download each file from each folder. I'd also like to make it so that I can control the number of folders it downloads at a time, e.g. if there's 100 folders, then be able to tell it to download folders 1-10, then at another point tell it to download folders 11-20.
    This is the code that I have so far:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.IO;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            WebClient wc = new WebClient();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                List<string> linkList = new List<string>();
                string url = textBox1.Text;
                string source = workerclass.getsource(url);
           
    
                int startindex = source.IndexOf("folder.gif");
                source = source.Substring(startindex, source.Length - startindex);
                while (source.IndexOf("<a href=") != -1)
                {
                    startindex = source.IndexOf("<a href=") + 9;
                    int endindex = source.IndexOf("/", startindex);
                    string link = source.Substring(startindex, endindex - startindex);
                    string fullink = url + link;
                    linkList.Add(fullink);
                    source = source.Replace("<a href=" + @"""" + link, "");
                }
                foreach (string link in linkList)
                {
    
                    List<string> linkList2 = new List<string>();
                    string newurl = textBox1.Text;
                    string source2 = workerclass.getsource(newurl);
    
    
                    int startindex2 = source.IndexOf("folder.gif");
                    source2 = source2.Substring(startindex, source2.Length - startindex2);
                    while (source2.IndexOf("<a href=") != -1)
                    {
                        startindex2 = source2.IndexOf("<a href=") + 9;
                        int endindex2 = source2.IndexOf("/", startindex);
                        string link2 = source.Substring(startindex2, endindex2 - startindex);
                        string fullink2 = newurl + link2;
                        linkList2.Add(fullink2);
                        source2 = source2.Replace("<a href=" + @"""" + link2, "");
                    }
                    foreach (string link2 in linkList2)
                    {
    
                        Uri reallink = new Uri(link2);
                        WebClient wc2 = new WebClient();
                        wc.DownloadFileAsync(reallink, link2+" file.zip");
    
                    }
                }
                
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
        }
    }
    Would this work to grab each file in each folder and download it? How would I tell it how many/which folders to download at one time as I previously mentioned?

  2. #2
    Join Date
    Dec 2009
    Posts
    18

    Re: Help with multi-file downloader

    You want to be able to download file 1-10 at the same time so your downloading all 10 at once?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center