0

I used below code to copy my folder in to startup folder it copying exe file correctly but not the folder and showing an unextension file simply, while exe is correctly copied

 string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
 if (Directory.GetCurrentDirectory() != startupFolder)
 {
     string ownPath = Assembly.GetExecutingAssembly().Location;
     File.Copy(ownPath, Path.Combine(startupFolder, "player.exe"));
     File.Copy(ownPath, Path.Combine(startupFolder, "player_Data"));
 }

player_Data is the folder name to be copied

Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40
Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
  • what is the problems in my question i have write a simple code. you provided me dozen of code – Muhammad Faizan Khan Oct 19 '16 at 10:50
  • 1
    What is the question here? Are you asking why `File.Copy` doesn't copy a folder? That's because it copies *files* as is evident by the class name and the documentation: "Copies an existing file to a new file.". – Lasse V. Karlsen Oct 19 '16 at 10:53
  • File != Directory – Tinwor Oct 19 '16 at 10:53
  • And the reason why Liam gave you "dozen of code" is because there's no single built in class or method in the .NET framework that copies a whole folder. You basically have to write the code yourself, or use code you find on the internet, such as the answer linked by Liam. – Lasse V. Karlsen Oct 19 '16 at 10:55
  • 2
    @MohammadFaizanKhan: Once you *understand* the code in the linked question, you might be able shorten it down to the parts that you actually need. If you have trouble understanding a particular instruction, we are here to help. – Heinzi Oct 19 '16 at 10:55
  • You can take a look at [FileSystem.CopyDirectory](https://msdn.microsoft.com/en-us/library/ms127957(v=vs.110).aspx), but if I remember correctly it has some shortcomings. – Lasse V. Karlsen Oct 19 '16 at 10:56
  • Your second File.Copy is copying the executing assembly to a file called player_data. If you want to copy a datafile the first parameter should identify the whole file name and the second should identify the whole target file name. – Kell Oct 19 '16 at 10:57
  • because File.Copy deals with files not with directory. for your purpose you have to first create directory then copy your file. – Vivek Nuna Oct 19 '16 at 11:06

0 Answers0