Search code examples
c#directoryinfo

Making a sub directory with a folder structure from part of a path


If I have a path, like so:

c:\windows\system32\inetsrv\abc.exe

And I want to make a folder under a drive/path such as

Z:\Stuff\

How can I make a sub directory and select whether I want everything from windows onwards, system32 onwards, or inetsrv onwards? BTW I know DirectoryInfo has a method called CreateSubDirectory().

Thanks


Solution

  • You can use System.IO.Directory.CreateDirectory(path). It is a static method unlike the DirectoryInfo one where you need an instance of a directory to call it.

    After that you could use Xcopy or Robocopy to copy all the files and subdirectories.