What's the best way to move directories and files?

Microsoft Windows
Post Reply
jason404
Posts: 10
Joined: 2022-Oct-16, 4:17 am

What's the best way to move directories and files?

Post by jason404 »

I want to move files and directories of files from one directory to another, which already contains some files and directories of files, maintaining the same directory structure.

I was using two for loops with the move command, once for directories and once for files, but I couldn't get it to work.

Should I use robocopy, or what is the best way to do this?

This is what I was using before, before I realised that it wasn't keeping the directory structure.

Code: Select all

if exist %USERPROFILE%\.config (
    for /f "tokens=*" %%a in ('dir /s /b "%USERPROFILE%\.config\*"') do move /y "%%~a" "%USERPROFILE%\winfiles\Settings\.config\"
    rmdir %USERPROFILE%\.config
)
User avatar
Simon Sheppard
Posts: 191
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: What's the best way to move directories and files?

Post by Simon Sheppard »

jason404 wrote: 2023-Oct-20, 12:31 pm Should I use robocopy
Yes Robocopy is made for this kind of task.
Post Reply