Alex Rivera | Logout

c# - Function to replicate the folder structure in the file path

Asked 2009-01-13T08:27:23.947
21

I need a simple function which will take a FileInfo and a destination_directory_name as input, get the file path from the fileinfo and replicate it in the destination_directory_name passed as the second parameter.

for ex. filepath is "d:\recordings\location1\client1\job1\file1.ext the function should create the directories in the destination_directory_name if they dont exist and copy the file after creating the directories.

Edit
Report

1 Answer

53

System.IO.Directory.CreateDirectory can be used to create the final directory, it will also automatically create all folders in the path if they do not exist.

//Will create all three directories (if they do not already exist).
System.IO.Directory.CreateDirectory("C:\\First\\Second\\Third")
answered 2009-07-18T10:51:32.963

Your Answer