How do I copy a folder’s attributes or replicate a folder structure without its contents?

0
19
Asked By TechWizard42 On

I'm trying to figure out how to copy a folder's attributes, like the hidden flag and creation date, to another folder or to simply replicate a folder structure without transferring any of its contents. I thought about using Robocopy, but it doesn't seem to create the destination folder when I'm trying to copy. For example, if I run Robocopy from C:Source to C:Dest, it won't create the C:Dest folder itself. Is there a way to do this effectively?

3 Answers

Answered By CommandLineNinja On

Make sure to adjust your Robocopy command to include the necessary attributes. Try `/COPYALL` to include all attributes, or if you want to specify, use `/COPY:DATSOU` and leave out the ones you’re not interested in. For just replicating the folder without data, you can opt for `/COPY:ATSOU` instead!

Answered By PowerShellPro On

If you're using PowerShell, you can achieve this by replicating the folder structure with some script. Use `Get-ChildItem` to grab all directories you want to copy and then create new folders at your desired location. Here’s a sample code to help you out!

$top_level_path = "C:Userspathtotop"
$new_top_level_path = "C:Usersnewpathtop"

$sub_paths = Get-ChildItem -Path $top_level_path -Recurse -Directory

foreach ($path in $sub_paths)
{
$new_path = $path.FullName -replace "C:\Users\path\to\top", $new_top_level_path
if (!(Test-Path -Path $new_path))
{
New-Item -Path $new_path -ItemType Directory
}
}

Answered By CodeCrusader88 On

You can actually use Robocopy for this! You need to specify the destination with the exact name of the source folder to copy the whole structure without the files. This should work for your case where you want to maintain the folder hierarchy. Just make sure you're directing it properly!

UserGuru33 -

Totally agree! Robocopy is a powerful tool for this.

FolderFanatic77 -

But keep in mind it doesn't copy the root folder itself. Using the `/create` flag can replicate the hierarchy, but it doesn’t give you the root folder. I've also noticed it creates 0 KB files, which is not what I want either. I'm really just after copying the main folder without any contents or attributes.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.