-1

If I have a string "C:\test\app\data\folder1\file.txt" and I know C:\test exists, what would be the best way to create each subfolder for the purpose of saving the file to the same folder within the same folder structure?

I could get the first position of "\" and check the string between that and the next occurrence, and do this for each subfolder in the string, but I'm just curious if there is a better way.

DarkW1nter
  • 2,933
  • 11
  • 67
  • 120
  • 2
    [`CreateDirectory`](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory?view=netframework-4.8) will create all of the directories along a path. There is no need to parse the path string. If you do need to pick apart the path then use the [`Path`](https://learn.microsoft.com/en-us/dotnet/api/system.io.path?view=netframework-4.8) class. – HABO May 07 '19 at 14:57

1 Answers1

1

system.io.directory.createdirectory

Creates all directories and subdirectories in the specified path unless they already exist.

Andy Nugent
  • 859
  • 7
  • 21