Go Premium for a chance to win a PS4. Enter to Win


MS-DOS xcopy makes it possible to COPY a newer file over an older one.  Is there an equivalent for MOVE?

Posted on 2010-09-05
Medium Priority
Last Modified: 2013-11-06
I have fallen into a classic problem in iTunes which raises a more general question.
I have all of my MP3s on my D:\ drive in D:\Music.  Having set the iTunes library folder to D:\Music, I now find a directory called D:\Music\Music
And having copied and backed up my files several times, I now have D:\Music\Music\Music, which is also full of music, much of it the same as higher up the tree.
Not quite sure how this has happened but I have seen it before.
I'm trying to consolidate all the files into the top level, D:\Music, before allowing iTunes to organise it all.
xcopy is great for copying only a newer file over an older.
But is there an equivalent for MOVE?  i.e. move the newer file over the older file, or if it's not newer just delete it?
Yes sure I could write a VBScript or a VBA macro but is there a one-line MS-DOS command that can do this?
Couldn't find anything obvious through Google.  Then again maybe I'm not looking hard enough.

So even though this arose through iTunes, it would be of generic use hence I felt it worth asking this illustrious grouping.
Question by:doowell
  • 6
  • 4
  • 3
  • +1
LVL 22

Expert Comment

ID: 33605832

If you want to move the files and not worry about any prompts (i.e. just move the file) then the /Y switch will always move the file


Expert Comment

by:Gary Stevens
ID: 33605843
I suggest you download a small but powerful program called 'SecondCopy' and use that to consolidate all your music into one (NEW) folder. You can run several profiles several times till it's put all you music together. I would run a separate profile for each sub directory putting the output into the root of the new Folder.
Give it a go. It;s free for 30 days and, like me if you like it, then it's a breeze to buy at US29.95
LVL 22

Expert Comment

ID: 33605853
Not sure if you already know, Move is a builtin command

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2
  [drive:][path]filename1 Specifies the location and name of the file
                          or files you want to move.
  destination             Specifies the new location of the file. Destination
                          can consist of a drive letter and colon, a
                          directory name, or a combination. If you are moving
                          only one file, you can also include a filename if
                          you want to rename the file when you move it.
  [drive:][path]dirname1  Specifies the directory you want to rename.
  dirname2                Specifies the new name of the directory.
  /Y                      Suppresses prompting to confirm you want to
                          overwrite an existing destination file.
  /-Y                     Causes prompting to confirm you want to overwrite
                          an existing destination file.
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.


Author Comment

ID: 33605855
Thanks for comment about MOVE command - yes I'm aware it's built in
What I'm after is instead of
xcopy <source> <target> /d /c /e /r /v /y

to have something like
move <source> <target> /d   <= where /d switch moves any newer files in source over the older files in target, but otherwise just deletes files in source
LVL 40

Expert Comment

by:Richard Quadling
ID: 33605876
Does the folder contain ONLY music files (mp3 and the like)? Or does it also contain data files for iTunes (I don't use iTunes).

If it is music only and if all you want to do is rename all files that are in D:\Music\Music\... to D:\Music\... then the following batch script will be of use to you.

If you run it, you should see the list of command that would be executed.

If you have many levels of "\Music", then running this script several times should fix things.

If you are happy with the commands, then remove the "ECHO " bits, leaving the rest of the line.

NOTE!!!!! For your own protection, please make sure you have adequate backups.
FOR /F "tokens=*" %%A IN ('DIR D:\Music\Music /a-d /s /b') DO (
	SET File=%%~A
	SET OldDir=%%~dpA
	SET NewDir=D:\!OldDir:~9!
	ECHO MD "!NewDir!"
	ECHO MOVE %%A D:\!File:~9!

Open in new window

LVL 22

Accepted Solution

chakko earned 1000 total points
ID: 33605896
robocopy  (in the Windows Resource Kit  - you can download it) can move only new/newer files and delete the source, but if the files already exists then it will skip the file but not delete from the source file.
example:   robocopy  c:\source c:\dest *.* /MOVE /XO
You could make a batch file to this.  The .doc file in the resource kit explains the errorlevel values returned by robocopy.  You can check if there was a copy error.  If any error then stop, if copy was successfull then delete the source folder
robocopy c:\source c:\dest *.* /MOVE /XO
if errorlevel 16 echo ***FATAL ERROR*** & goto end
if errorlevel 15 echo FAIL MISM XTRA COPY & goto end
if errorlevel 14 echo FAIL MISM XTRA & goto end
if errorlevel 13 echo FAIL MISM COPY & goto end
if errorlevel 12 echo FAIL MISM & goto end
if errorlevel 11 echo FAIL XTRA COPY & goto end
if errorlevel 10 echo FAIL XTRA & goto end
if errorlevel 9 echo FAIL COPY & goto end
if errorlevel 8 echo FAIL & goto end

rem assume no error so delete source folder
del c:\source\*.* /F /S /Q


Author Comment

ID: 33605899
Great script and I guess answers my request for a one-line command with a "no it's not possible"

Anyone else?

I'll award points by Tuesday if no further contributions.


Author Comment

ID: 33605907
Ah and of course in the time I wrote that the robocopy idea appeared.  Looks good, will check it out.
LVL 22

Expert Comment

ID: 33605908
I don't think it's possible with a one line command or without some utility program.
robocopy will skip already existing/same files to cut the copy time
but the batch file will be a one line command to execute

Assisted Solution

by:Gary Stevens
Gary Stevens earned 1000 total points
ID: 33605912
Another option comes to mind.
Robocopy has much of the functionality you seek. It also allows to only overwrite if newer than the existing file.

Author Comment

ID: 33605956
I was always scared of Robocopy for some reason - can't put my finger on why - but you're quite right, it does what I need.
Now I guess I should give points to more than one response...

Author Closing Comment

ID: 33605958
Should have figured this out myself!
Thanks to all.
Presumably I should start to learn PowerShell.
LVL 40

Expert Comment

by:Richard Quadling
ID: 33609739
Is there a reason why my answer wasn't examined?

The batch script I gave would effectively remove 1 \music from all the files in \music\music

RoboCopy would do the same (I'm pretty sure) and be better in terms of reporting.

No need to learn PowerShell ... unless you want to!

Author Comment

ID: 33609757
No reason it's just that it wasn't a one-line solution which is what I was after

Thanks anyway!
LVL 40

Expert Comment

by:Richard Quadling
ID: 33609857
Ah. OK. I got it working (more or less) in 1 line, but it is nothing more than ...

command && command && command && command

sort of thing.

It's not perfect as I have to put the command line into a batch file to get the delayed variable expansion to operate appropriately.


Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Smartwatches: just a fashion accessory or a useful device for all? The Apple Watch (http://www.apple.com/watch/) was launched in April of 2015 and has become a new way for iPhone users to stay connected. Ranging from $349 to $17,000, the Apple Watch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question