General discussion

  • Creator
  • #2209431

    Copy newest file


    by cmm8907 ·

    I need a bat file that will copy only the newest file in a directory. I currently have this:
    FOR /F “delims=” %%I IN (‘DIR C:\source*.* /B /O:-D’) DO COPY “%%~fI” “C:\destination”

    This will sort all files in the directory and then copy them all in order of modified or created date starting with the newest one.

    Basically I need it to stop after it copies that first file.

    Any suggestions?

All Comments

  • Author
    • #2444440

      Repost as ‘Q&A’

      by hal 9000 ·

      In reply to Copy newest file

      Try reposting this in the ‘Q&A’ forum. The ‘Discussion’ forum is for matters of general discussion, not specific problems in search of a solution. The ‘Water Cooler’ is for non-technical discussions. You can submit a question to ‘Q&A’ here:;content

      There are TR members who specifically seek out problems in need of a solution. Although there is some overlap between the forums, you’ll find more of those members in ‘Q&A’ than in ‘Discussions’ or ‘Water Cooler’.

      Be sure to use the voting buttons to provide your feedback. Voting a ‘+’ does not necessarily mean that a given response contained the complete solution to your problem, but that it served to guide you toward it. This is intended to serve as an aid to those who may in the future have a problem similar to yours. If they have a ready source of reference available, perhaps won’t need to repeat questions previously asked and answered. If a post did contain the solution to your problem, you can also close the question by marking the helpful post as “The Answer”. .

Viewing 0 reply threads