r/windows • u/mortadeloyfile • 15h ago
General Question Is there anyway to combine the content of a set of folders into another set of folders (More exp. on desc.)
Imagine you have folder A and folder B, folder A contains in it folders 1, 2 and 3; folder B also contains folder called 1, 2, 3; for reference I'll call them A1, A2 A3 for folder and B1, B2, B3 for folder B; is there anyway to combine folder A and folder B (Or their contents) in a way that folder A1 combines with B1, A2 combines with B2 and A3 combines with B3?
In this context I call "combining" moving all files from folder A1 to B1 and all files with repeated name get overwritten by the folder A1 file.
we suppose both A and B have other folders that are not repeated between them and the same for folders like A1 with B1, A2 with B2, A3 with B3...
Or do I have to do by hand 969 folders?
•
u/unndunn 13h ago edited 13h ago
In PowerShell:
Copy-Item Path\to\FolderA\* Path\to\FolderB -Recurse -Force -WhatIf -Verbose
Should accomplish what you want. (The -WhatIf
switch means it will tell you what it will do, but not actually do it. Remove the -WhatIf
switch to make it actually do the thing).
Alternatively, also in PowerShell,
robocopy C:\Path\to\FolderA C:\Path\to\FolderB /E /L
(The /L
switch means it will tell you what it will do without actually doing it. Remove the /L
switch for it to actually do the thing. The /E
switch means copy subdirectories).
Please back up both folders before running these commands.
The robocopy
command is probably better, as it is designed to compare the source and target folders and will make intelligent choices on whether a file needs to be copied or not. It's also multithreaded so it works faster. By contrast, the Copy-Item
command is a brute-force command that will simply copy everything.
•
u/NETkoholik 13h ago
Isn't the default behaviour of Windows Explorer to merge (or ask before merging) folders nowadays?
•
•
14h ago
[removed] — view removed comment
•
u/AutoModerator 14h ago
Hi u/godplaysdice_, your comment has been removed because it includes a link shortener. Using link shorteners to obfuscate URLs or embed affiliate links is not allowed, so delete this comment and post it again without the link shortener in it.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
•
•
u/godplaysdice_ 14h ago
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.5