David Gonzalez
David Gonzalez

Reputation: 37

Move desktop files to a folder using cmd

I wanted to make a windows command line script that moves all of the user data into a folder. I stared with moving all the files from the desktop into a folder Its working with xcopy but i revive some errors while using move.

@echo on
set SOURCE=C:\Users\%username%\Desktop
set DESTINATION=C:\dir2
xcopy "%SOURCE%\*" "%DESTINATION%\*"  /y
pause

This works with xcopy but when I change it to move the syntax breaks. Why is it happening?

Upvotes: 2

Views: 1458

Answers (2)

Rishav
Rishav

Reputation: 4068

There is a minor glitch in your code.
You can't use the asterisk (*) placed after the %Destination% while moving. Instead use the following code. If you don't want a prompt use /Y

@echo on
set SOURCE=D:\old
set DESTINATION=D:\new
move /Y "%SOURCE%\*" "%DESTINATION%\" 
pause

Upvotes: 1

Filipus
Filipus

Reputation: 540

For the MOVE command, the /Y option has to be specified before the source file names.

So instead, use :

move /Y "%SOURCE%\*" "%DESTINATION%\*"

Upvotes: 0

Related Questions