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:
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?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) { } } }


Reply With Quote
Bookmarks