Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy entire directory to output folder maintaining the folder structure?

I want a specific directory to be copied to output folder ("bin") on every build. I think it can be handled via post build scripts. But I'm not sure how to copy a directory itself. I know how to handle specific files.

For eg, this works for a file:

In

Project > Properties > Build Events> Post Build

COPY "$(SolutionDir)Resources\Release Notes.pdf" "$(TargetDir)" 

But suppose I have a directory Template, now I need everything under Template to come to bin folder upon successful build maintaining the folder structure.

I tried this:

COPY "$(SolutionDir)Resources\Template\" "$(TargetDir)" 

Only the files in Template directory gets copied this way and not the sub directories and the files inside Template folder. I want the folder Template itself to come inside my output bin folder. In other words, bin should look like:

bin > Template > abc.xxx                    xxx.yyy                  Subdirectory1 > asd.qwe                                  zxc.qwe                   Subdirectory2 > ... 

This could be a duplicate, but I couldn't find a relevant thread. Thanks.

like image 678
nawfal Avatar asked Jul 19 '13 09:07

nawfal


People also ask

How do you copy and entire directory structure?

Type "xcopy", "source", "destination" /t /e in the Command Prompt window. Instead of “ source ,” type the path of the folder hierarchy you want to copy. Instead of “ destination ,” enter the path where you want to store the copied folder structure. Press “Enter” on your keyboard.

How do I copy an entire directory to a destination folder?

In Windows 10 and earlier versions, right-click the folder and select Copy, or click Edit and then Copy. Navigate to the location where you want to place the folder and all its contents. icon on the menu bar. Alternatively, right-click the folder, select Show more options and then Paste.

What is the command to copy directory structure?

Use the cp command to create a copy of the contents of the file or directory specified by the SourceFile or SourceDirectory parameters into the file or directory specified by the TargetFile or TargetDirectory parameters.


Video Answer


2 Answers

I just added this to my *.csproj file (right click Edit Project File)

<ItemGroup>     <Content Include="MYCUSTOMFOLDER\**">         <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>     </Content> </ItemGroup> 

I think for this the directory needs to be on same hierarchy level as *.csproj file or bellow that.

like image 100
CodingYourLife Avatar answered Sep 17 '22 13:09

CodingYourLife


This worked for me. /S is the key which copies everything recursively.

XCOPY "$(SolutionDir)Resources\Template" "$(TargetDir)\Template\" /S 

Since I wanted files to be overwritten every time without a prompt, I added a /Y switch as well.

XCOPY "$(SolutionDir)Resources\Template" "$(TargetDir)\Template\" /S /Y 
like image 33
nawfal Avatar answered Sep 18 '22 13:09

nawfal