Z
Z
zenox022021-09-27 15:46:06
C++ / C#
zenox02, 2021-09-27 15:46:06

System.IO.DirectoryNotFoundException: Part of the path could not be found. What to do?

for (int z = 2; z <= 15; z++)
            {
                File.Copy(@"C:\Users\ZeNoX\source\repos\sus\sus\Resources\peele.jpg", [email protected]"C:\Users\{Environment.UserName}\Desktop\sus({z}).jpg");
              

            }


On my PC it works, but on the virtual machine I get an error

6151bc7173aec824376861.png

. I tried to put a photo in the exe itself, or in the project folder, but still the same error. I need it to work on other PCs as well as on mine. Copied the image to the desktop

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-09-27
@vabka

You put the image in the properties so that it is always copied to the target folder during the build.
And then you do this:

var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var targetPath = Path.Combine(desktop, "sus(42).jpg");
File.Copy(@"./Resources/peele.jpg", targetPath);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question