Cmd line instruction to move selected files from sub-folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MartinR
Posts: 2
Joined: 23 Feb 2015 10:59
Location: UK

Cmd line instruction to move selected files from sub-folders

#1 Post by MartinR » 23 Feb 2015 12:45

Hi! I apologise in advance if this is something that I should have been able to work out for myself, but I've got to the point where my imagination has run out of options!

I am trying to move files from a folder named "Photos" and its numerous sub-folders. The common denominator is that the files to move all contain "-2.cr2". I want to move them (not copy) to another folder on the same drive, named "CR2DUpes.". I am using the following:
C:\>move/f e:\photos\/s *-2.cr2 e:\cr2Dupes and I get:"The syntax of the command is incorrect."

I have tried doing a DIR query using similar syntax and that works OK - I have tried re-positioning the "/s" option.

As you will have realised, I am not skilled at this! Can anyone please tell me where I am going wrong?

Many thanks,

Martin

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Cmd line instruction to move selected files from sub-fol

#2 Post by Squashman » 23 Feb 2015 14:38

Move does not have an /S or /F option if you happened to read the help file.

Code: Select all

H:\>move /?
Moves files and renames files and directories.

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.

The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless MOVE command is being executed from
within a batch script.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Cmd line instruction to move selected files from sub-fol

#3 Post by foxidrive » 23 Feb 2015 17:18

This should help - there are caveats in that it also matches in the short filename.

Code: Select all

@echo off
md "e:\cr2Dupes" 2>nul
for /r "e:\photos\" %%a in (*-2.cr2) do (
  echo  move "%%a" "e:\cr2Dupes"
)
pause

MartinR
Posts: 2
Joined: 23 Feb 2015 10:59
Location: UK

Re: Cmd line instruction to move selected files from sub-fol

#4 Post by MartinR » 25 Feb 2015 03:31

Thank you for the prompt answers & help.

I had read the Help file and I was aware of the "Y" in the move - I suffered memory/typing error I'm afraid. I used the /S to find the sub-directories.

However, problem solved. Thanks again.

Martin

Post Reply