Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 8
    Default delimiters are <tab> and <space> so it is better to add "delims=" after FOR /F to accept filenames with spaces. Whole command will be FOR /F "delims=" %%I IN ('DIR . /B /O:-D') DO COPY %%I <<NewDir>> & EXIT
    – Cheburek
    Commented Oct 13, 2010 at 22:16
  • 1
    Note that the space in front of the & becomes part of the previous command. That has bitten me with SET, which happily puts trailing blanks into the value.
    – Chris Noe
    Commented Mar 5, 2011 at 19:15
  • 2
    @Ashwin: %%I is the value from DIR *.* /B /O:-D -- so for each iteration of the loop it is the filename. Since the loop exits on its first iteration, it's only value is the first file (with a dot in its name) in the directory.
    – idbrii
    Commented May 24, 2012 at 22:41
  • Hi All. How do I filter by Date only and not Date and Time? /O:-D Commented Feb 3, 2014 at 14:00
  • 3
    @idbrii "(with a dot in its name)" < no because *.* in Windows has special behavior to match also files without dot, same as *. (Incidentally, even something like *.*.*.* does.)
    – CherryDT
    Commented Jul 4, 2021 at 9:56