Solved

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
15
875 Views
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.
0
Comment
Question by:doowell
  • 6
  • 4
  • 3
  • +1
15 Comments
 
LVL 22

Expert Comment

by:chakko
Comment Utility

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


0
 
LVL 6

Expert Comment

by:Gary Stevens
Comment Utility
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
Cheers
Gary
0
 
LVL 22

Expert Comment

by:chakko
Comment Utility
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.
 
0
 

Author Comment

by:doowell
Comment Utility
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
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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.
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

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

0
 
LVL 22

Accepted Solution

by:
chakko earned 250 total points
Comment Utility
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.
 
http://www.mysidenotes.com/2008/02/15/robocopy-errorlevel-return-codes-found-in-robocopydoc/
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
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

:end
0
 

Author Comment

by:doowell
Comment Utility
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.

Cheers.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:doowell
Comment Utility
Ah and of course in the time I wrote that the robocopy idea appeared.  Looks good, will check it out.
0
 
LVL 22

Expert Comment

by:chakko
Comment Utility
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
 
0
 
LVL 6

Assisted Solution

by:Gary Stevens
Gary Stevens earned 250 total points
Comment Utility
doowell
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.
GS
0
 

Author Comment

by:doowell
Comment Utility
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...
0
 

Author Closing Comment

by:doowell
Comment Utility
Should have figured this out myself!
Thanks to all.
Presumably I should start to learn PowerShell.
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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!
0
 

Author Comment

by:doowell
Comment Utility
No reason it's just that it wasn't a one-line solution which is what I was after

Thanks anyway!
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
A lot of new and distinct gadgets are making their appearance every other day. The latest gadget that has wooed the attention of all gadget lovers and non gadget lovers alike is the Smartwatch. This tiny gadget is capable of offering live access to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now