How Can I Copy a Folder’s Attributes or Create an Empty Folder Without Content?

0
20
Asked By CuriousCoder42 On

I'm trying to find a way to copy a folder's attributes such as the hidden flag and creation date to a different folder. Alternatively, I'd like to create a new folder that mimics the structure of an existing folder but without copying any of the content. I've been exploring Robocopy for this, but I'm having some trouble. For instance, when I use the command `robocopy C:Source C:Dest`, it doesn't create the destination folder itself, so I could use some guidance. Any tips?

3 Answers

Answered By ScriptedSam On

For creating an empty folder structure, try this PowerShell script. It replicates the folder under a new parent. You just need to define the top-level source and the new destination. It finds all the directories and creates them without copying any file content. Here's a quick snippet:

```powershell
$top_level_path = "C:pathtosource"
$new_top_level_path = "C:pathtonew"
Get-ChildItem -Path $top_level_path -Recurse -Directory | ForEach-Object {
$newPath = $_.FullName -replace [regex]::Escape($top_level_path), $new_top_level_path
New-Item -Path $newPath -ItemType Directory -ErrorAction SilentlyContinue
}
```

This should create your desired folder structure!

Answered By TechieTim On

You can actually use Robocopy to replicate the folder structure without the files. To copy the hierarchy without content, just ensure you're specifying the destination with the full folder name. This will bring over the structure you're looking for! If you're aiming for specific attributes, consider using the `/create` flag to avoid unwanted data copying. Just remember to adjust your destination correctly.

Answered By PowershellGuru88 On

If you want to ensure you’re including specific attributes with Robocopy, make sure to use `/COPYALL`. This will grab everything. However, if you only want certain attributes like the date and hidden flag, you can specify them individually with `/COPY:DATSOU`, which allows you to exclude the data. So for your needs, try `/COPY:ATSOU` to exclude files.

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.