Aks
Aks

Reputation: 5236

File.AppendAllText create subdirectory if doesn't exist?

If I have a path C:\Test\Test1\a.txt and Test1 doesn't exist, how can I ensure it is created before appending to a.txt?

Upvotes: 15

Views: 5778

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500805

How about:

Directory.CreateDirectory(Path.GetDirectoryName(filename));

Upvotes: 21

Related Questions