Windows – Copy file names with a certain number of characters in command line (CMD)

cmd.execommand linedirregexwindows

I need to copy all text files on one folder whose names are five characters long. I know this command is for listing:

$ dir folder /B | findstr /R "^.....\.txt"

but I want to copy all files whose names are listed by the above command
to a different folder.

Best Answer

I was asking (not only to myself) "doesn't it work a simple..."?

copy  C:\ORIG_DIR\?????.txt C:\Dest_Dir

Thanks to G-Man it is tested that in powershell it works, meanwhile in cmd.exe the above command will copy each match up to five characters and with all the extension that start with .txt.

Question mark (?)

Use the question mark as a substitute for a single character in a name. For example, if you type gloss?.doc, you will locate the file Glossy.doc or Gloss1.doc but not Glossary.doc.

Reference:

Related Question