• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

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

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.
  • 6
  • 4
  • 3
  • +1
2 Solutions

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

Gary StevensConsultantCommented:
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
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.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

doowellAuthor Commented:
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
Richard QuadlingSenior Software DeveloperCommented:
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

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

doowellAuthor Commented:
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.

doowellAuthor Commented:
Ah and of course in the time I wrote that the robocopy idea appeared.  Looks good, will check it out.
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
Gary StevensConsultantCommented:
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.
doowellAuthor Commented:
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...
doowellAuthor Commented:
Should have figured this out myself!
Thanks to all.
Presumably I should start to learn PowerShell.
Richard QuadlingSenior Software DeveloperCommented:
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!
doowellAuthor Commented:
No reason it's just that it wasn't a one-line solution which is what I was after

Thanks anyway!
Richard QuadlingSenior Software DeveloperCommented:
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now