copy directory including 'base' folder
Solution 1
try
xcopy folder1 folder2\folder1 /e /i
Solution 2
robocopy \folderA \folderB\folderA /s
will create folderA at the destination and perform a recursive copy. Check what other options you may want or require. e.g. /e
if you want to include empty folders.
Related videos on Youtube
Nikhil Komalan
a cloud-based block chain enabled disruptive distributed ledger encompassing big data </sarcasm> some handy things i keep forgetting find all services with name sc queryex type= service state= all | find /i "service-name" enable telnet client (from admin prompt) dism /online /Enable-Feature /FeatureName:TelnetClient
Updated on September 18, 2022Comments
-
Nikhil Komalan over 1 year
I need to copy folderA into folderB via the command line:
c:\temp \folderA \folderB
should become
c:\temp \folderA \folderB\folderA
That is, exactly the same as if you copied folderA using windows explorer and pasted it into folderB.
This does not work:
xcopy /e folder1 folder2\
as you end up with the contents of folderA in folderB and not folderA itself.
Funnily enough,
move
does exactly what I want except that it moves instead of copy :)How do you copy a folder and include the folder itself as the base folder for the copy? I shouldn't have to use mkdir to create the target folder. (but that gets the job done nastily)
Please dont direct me to this as that does not do the above.
Update:
Thanks to the answers below using robocopy I found a solution using xcopy that doesnt prompt either:
xcopy /e /i folderA folderB\folderA
Use the
/i
option to avoid being asked whether the target is a directory or a file. -
Nikhil Komalan almost 12 yearsthat doesnt work did you even try it? does exactly the same as xcopy command above, folderA is not copied.