You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Web.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace TensorFlowNET.Examples.Utility
  10. {
  11. public class Web
  12. {
  13. public static bool Download(string url, string destDir, string destFileName)
  14. {
  15. if (destFileName == null)
  16. destFileName = url.Split(Path.DirectorySeparatorChar).Last();
  17. Directory.CreateDirectory(destDir);
  18. string relativeFilePath = Path.Combine(destDir, destFileName);
  19. if (File.Exists(relativeFilePath))
  20. {
  21. Console.WriteLine($"{relativeFilePath} already exists.");
  22. return false;
  23. }
  24. var wc = new WebClient();
  25. Console.WriteLine($"Downloading {relativeFilePath}");
  26. var download = Task.Run(() => wc.DownloadFile(url, relativeFilePath));
  27. while (!download.IsCompleted)
  28. {
  29. Thread.Sleep(1000);
  30. Console.Write(".");
  31. }
  32. Console.WriteLine("");
  33. Console.WriteLine($"Downloaded {relativeFilePath}");
  34. return true;
  35. }
  36. }
  37. }