Advertisement
kamil2321

Przenoszenie plików i folderów z timerem

Jan 5th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. // Do buttona:
  2.             string katalog_skad_przenosic = @".\SkyGfx_SA_patch\SkyGfx_SA_4.1";
  3.             string katalog_do_usuniecia = @".\SkyGfx_SA_patch";
  4.             string katalog_o_dwa_nizej = @".\"; //czyli tam gdzie .exe
  5.  
  6.             foreach (string dir in Directory.GetDirectories(katalog_skad_przenosic, "*", SearchOption.AllDirectories))
  7.             {
  8.                 Directory.CreateDirectory(Path.Combine(katalog_o_dwa_nizej, dir.Substring(katalog_skad_przenosic.Length + 1)));
  9.             }
  10.             foreach (string file_name in Directory.GetFiles(katalog_skad_przenosic, "*", SearchOption.AllDirectories))
  11.             {
  12.                 Directory.Move(file_name, Path.Combine(katalog_o_dwa_nizej, file_name.Substring(katalog_skad_przenosic.Length + 1)));
  13.             }
  14.             Wait(3000); // Użycie: 3000ms = 3s
  15.             // Po 3 sekundach usuwa folder
  16.             Directory.Delete(katalog_do_usuniecia, true);
  17.  
  18. // Nad buttonem, wywołujący powyższy kod dodaj:
  19.         public void Wait(int time)
  20.         {
  21.             System.Threading.Thread thread = new System.Threading.Thread(delegate ()
  22.             {
  23.                 System.Threading.Thread.Sleep(time);
  24.             });
  25.             thread.Start();
  26.             while (thread.IsAlive)
  27.                 Application.DoEvents();
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement