I have created a batch file to be executed through the right-click menu in Win7. When I right-click on a folder, I would like the batch file to move all files (excluding folders) up 1 directory. I have this so far:

MOVE "%1\*.*"  ..\

This seems to work as long as the folder I'm moving files from doesn't have any spaces. When the folder does have spaces, I get an error message: "The syntax of the command is incorrect."

So my batch works on a folder titled PULLTEST but not on a folder titled PULL TEST.

Again, I don't need it to move folders, just files. And I would like it to work in any directory on any drive. There will be no specific directories that I will be working in. It will be random.

Below is the registry file I made if needed for reference.

Windows Registry Editor Version 5.00


@="\"C:\\Program Files\\MyBatchs\\PullFiles.bat\" \"%1\""
  • Every time someone talks about the Windows command line interface as "DOS", a kitten dies... – a CVn Aug 18 '14 at 20:05

The batch could be as simple as this one liner:

@move "%~1\*" "%~1\.."

The tilde removes any enclosing quotes that may already by present in the argument value. The extra set of quotes were the source of your problem.

EDIT - You don't say what you want to happen if a file with the same name already exists in the parent directory. Since the MOVE command is in a batch file, the default is to automatically overwrite the file in the parent folder. If you want the script to prompt for instruction, giving you the opportunity to prevent the overwrite, then you need the /-Y option.

@move /-y "%~1\*" "%~1\.."
| improve this answer | |
  • Doesn't this also move folders? all files (excluding folders). But nevertheless, the OP's version (*.*) also doesn't prevent this from happening because folder names can contain dots – nixda Aug 18 '14 at 16:31
  • 1
    @nixda - MOVE will only move folders if explicitly listed. It will never move a folder if wildcards are used. Also, *.* matches any file, including files without extensions (no dots). – dbenham Aug 18 '14 at 17:21
  • Ah, good to know – nixda Aug 18 '14 at 17:43

You spelt pushd command wrong, you have two h.

And you have to remove %1 from move command. If the directory has spaces, move command becomes broken.

Assume your batch is named MoveFiles.bat. It is called like this:

MoveFiles.bat "C:\Test\With Spaces"

After parameter substitution inside the batch, it looks this way:

PUSHD "C:\Test\With Spaces"
MOVE ""C:\Test\With Spaces"*.*" ..\

The second command has syntax error because of nested quotes.

This version of batch works for me:

MOVE *.* ..\
| improve this answer | |
  • 1
    +1 The nested quotes is not a syntax error, but it is the source of the problem. For example, an extra set of quotes using ""%1\*.*"" would work, but it is not recommended. – dbenham Aug 18 '14 at 16:24
  • @dbenham Sure! Quotes were incorrectly nested :) – Alexey Ivanov Aug 19 '14 at 17:32

The reason it's throwing that error is because of the spaces. pushd works with spaces, but move doesn't. Try enclosing your second argument, ..\, with quotes:

MOVE "%1*.*" "..\"
| improve this answer | |
  • 1
    Adding quotes around ..\ won't help here because the error is caused by double quotes in the first parameter to move because %1 already has quotes. – Alexey Ivanov Aug 18 '14 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.