1

I am using the "move" command with a wildcard pattern in the CMD prompt under Windows 7.

In my source directory, I have the following files:

 movie1.avi
 movie1.avi_metadata
 movie2.avi
 movie2.avi_metadata

If I type the command move source\*.avi dest it will move all four files even though I would expect it to only move the two *.avi files and not the *.avi_metadata files.

As expected, move source\*.a dest and move source\*.av dest don't move any files. However when the length of the extension for the wildcard pattern is 3 characters, it will move all extensions that begin with those first three characters.

Is this a bug in the "move" command or expected behavior and is it documented anywhere?


Edit: John Watts notes that this is probably do to "short" filenames.

Is it possible then to make commands in the CMD interpreter only operate on long filenames and to ignore short filenames?

Adisak
  • 291
  • 3
  • 9
  • 2
    Does windows 7 still create 8.3 names? Because those would match *.avi for all four files. –  Aug 30 '12 at 16:03
  • Ah... short file names... you bite me in the butt. Thanks John. BTW, I wonder who downvoted this. It's a legitimate question. – Adisak Aug 30 '12 at 16:04
  • It probably belongs on superuser. It is more appropriate to move it than downvote, but they may not have enough rep for that. –  Aug 30 '12 at 16:07
  • Well, it's certainly something that affects BATCH programming. I'm not even sure how to move it to a different StackExchange site :-( – Adisak Aug 30 '12 at 16:11
  • See [this rule from MS DOS](http://blogs.msdn.com/b/oldnewthing/archive/2007/12/17/6785519.aspx), still relevant today for compatibility. – Christian.K Aug 30 '12 at 17:49
  • 2
    you could disable creation of short filenames on ntfs using fsutil: `fsutil behavior set disable8dot3 1`. This affects only files created after the change. – wmz Aug 30 '12 at 18:55
  • Possible duplicate of [Move a file to archive folder in cmd using wildcards](https://superuser.com/q/517486/173513) and [How does the Windows RENAME command interpret wildcards?](https://superuser.com/q/475874/173513) – jww Oct 07 '18 at 21:03

1 Answers1

2

You can pipe DIR /B through FINDSTR to filter out the unwanted files. You can process those results using FOR /F.

for /f "eol=: delims=" %F in ('dir /b /a-d source\*.avi^|findstr /lie .avi') do move "source\%F" dest
dbenham
  • 11,194
  • 6
  • 30
  • 47