Home c# does not want to create a folder when copying a C #...

does not want to create a folder when copying a C # System.io file

Author

Date

Category

Copy file using:

file.copy (file.frompath, file.inpath, true);

But if it comes across a path with a non-existent folder, let’s say

file.copy (@ "f: \ test \ text.txt", @ "f: \ test \ text .txt ", True);

(on the disk F, there is no such folder), then an exception is caused. How can I deal with it and is there another way to copy files? Or you need to manually create folders … I don’t want somehow.


Answer 1, Authority 100%

You need to create folder structure before copying.

directory.createdirectory (path.getdirectoryname (file.inpath));
File.copy (file.frompath, file.inpath, true);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions