Advertisement
retesere20

copy file to startup

Jul 26th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. private void copyBat()
  2. {
  3. try
  4. {
  5. string source_dir = "c:\\Debug";
  6. string destination_dir = "C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
  7.  
  8. if (!System.IO.Directory.Exists(destination_dir))
  9. {
  10. System.IO.Directory.CreateDirectory(destination_dir);
  11. }
  12.  
  13. // Create subdirectory structure in destination
  14. foreach (string dir in Directory.GetDirectories(source_dir, "*", System.IO.SearchOption.AllDirectories))
  15. {
  16. Directory.CreateDirectory(destination_dir + dir.Substring(source_dir.Length));
  17.  
  18. }
  19.  
  20. foreach (string file_name in Directory.GetFiles(source_dir, "*.*", System.IO.SearchOption.AllDirectories))
  21. {
  22. File.Copy(file_name, destination_dir + file_name.Substring(source_dir.Length), true);
  23. }
  24. }
  25.  
  26. catch (Exception e)
  27. {
  28. MessageBox.Show(e.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement