Skip navigation

Recently, I needed to download a lot of files that I had in a file on my computer, so I threw together a quick console program to download files given a text file with the URLs in it. It worked first time around perfectly, and Im quite proud of it, I think that other people could use this program, here is the source for it…

            List<string> files=new List<string>();

            System.Net.WebClient downloader = new System.Net.WebClient();

 

            string location=Console.ReadLine();

            StreamReader filereader = new StreamReader(location);

 

            while (!filereader.EndOfStream)

            {

                files.Add(filereader.ReadLine());

            }

 

            foreach (string n in files)

            {

                try

                {

                    Console.Write(“downloading file “+ n + “: “);

                    downloader.DownloadFile(n, Path.GetFileName(n));

                    Console.WriteLine(“Done”);

                }

                catch (Exception x)

                {

                    Console.WriteLine(“failed, reason: “+ x.ToString());

                    throw;

                }

            }

 

            Console.WriteLine(“done!”);

            Console.ReadLine();

its pritty self explanitory, and it did what I want it to, so I didnt really test it that much

Blogged with Flock

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: