City
City

Reputation: 33

CMD/BATCH move all folders and subfolders

I am looking for a way to move a folder including subfolders to a new location

old location: C:\Users\test\OneDrive

new location: c:\new

The command below moves all files in the root folder C:\Users\test\OneDrive to the new location, but all subfolders are missing

move C:\Users\Hiss\OneDrive\*.* c:\new

Upvotes: 2

Views: 19473

Answers (1)

Riegardt Steyn
Riegardt Steyn

Reputation: 5711

You can use two for statements (one for the files and one for the folders):

echo off
for %%a in ("%1\*") do move /y "%%~fa" %2
for /d %%a in ("%1\*") do move /y "%%~fa" %2

Put that in a batch file (e.g. MoveContents.bat), and run with parameters:

MoveContents.bat C:\Users\Hiss\OneDrive\ c:\new

Upvotes: 1

Related Questions