In batch files like this simple example mx.cmd
md "%1 %2"
move *%1?%2*.* "%1 %2"
move *%2?%1*.* "%1 %2"
move *%2,?%2*.* "%1 %2"
The move command often moves files that it shouldn't because the real file names don't match *%1*%2*.* but the short file names do.
So ... how do I tell commands like Copy and Move to ignore the short file names and only use the real file names?
%1 and %2 are generally a person's first and last names. The most common failures of my little batch files are when I only have initials to work with instead of full names. For example:
"mx J Doe" is likely to cause files to be inappropriately moved but ...
"mx John Doe" is very unlikely to do so.
Another common failure point is when I _do_ have full names of the person to work with but those names are short, such as "Jin Wu".
I often call little batch files like that mx.cmd thousands of times from within a much larger batch file and having to manually check and rectify those inappropriate file moves is a real pain in the butt.
How to make Copy, xCopy & Move ignore short file names?
Moderator: DosItHelp
Re: How to make Copy, xCopy & Move ignore short file names?
This eliminates short filenames - and long filenames with ~ in them.
Code: Select all
md "%1 %2"
for /f "delims=" %%a in ('dir "*%1?%2*" "*%2?%1*" "*%2,?%2*" /b /a-d ^|findstr /v "~" ') do (
move "%%a" "%1 %2"
)
Re: How to make Copy, xCopy & Move ignore short file names?
Many thanks foxidrive - I'm looking forward to trying that out next time I have a big batch of files to clean up and organize.