Question

  • Creator
    Topic
  • #2245867

    create batch file to select *.txt created today and copy to other folder

    Locked

    by kanignu ·

    i’m trying to select the *.txt files created today in c:\users folder and then xcopy it to another folder in the system. the code i came up with is below but it doesnt run. can you help me fix the issue

    forfiles /p c:\Users /m *.txt /d -0 /c “xcopy c:\Users c:\Users\kanishka /v /s /y”

All Answers

  • Author
    Replies
    • #2851252

      Clarifications

      by kanignu ·

      In reply to create batch file to select *.txt created today and copy to other folder

      Clarifications

    • #2851236

      Not sure what you’re using.

      by neilb@uk ·

      In reply to create batch file to select *.txt created today and copy to other folder

      Never heard of ‘forfiles’

      However…

      for /F %%i in (‘dir /b c:\Users\*.txt’) do copy c:\Users\%%i c:\Users\kanishka

      will do what I think you want

      • #2851063

        This worked nicely

        by kanignu ·

        In reply to Not sure what you’re using.

        This worked as a charm!! but i need to be able to select the files based on the created date. in other words i only need to select *.txt files created on that day

        • #2851045

          OK, here’s what you do

          by neilb@uk ·

          In reply to This worked nicely

          You can’t – unfortunately – filter the DIR /B info because you don’t have the date information.

          Instead of “COPY”, use Microsoft’s ROBOCOPY and include the /MAXAGE:1 switch and that will limit the copy to files up to a day old.

          You can also use XCOPY with the /D:DD-MM-YY (or it may be MM-DD-YY, I can’t remember) and you get the date by the following bit of batch file stuff:

          FOR /F “tokens=1,2,3* Delims=/ ” %%I in (‘DATE /T’) DO set TODAY=%%I-%%J-%%K

          Note that gets you whatever format DATE /T gets you! No idea which way round the dates should be so experiment.

          You can then use /D:%TODAY% in the XCOPY command.

        • #2861010

          Can Make this Work

          by kanignu ·

          In reply to OK, here’s what you do

          I think i can use the Robocopy /Maxage:1 option Thanks for pointing me at the right direction

    • #2851035

      “Today” or “Not copied since last modified”?

      by oldbaritone ·

      In reply to create batch file to select *.txt created today and copy to other folder

      I’m just wondering if the actual requirement says “today” or if you are supposed to copy files that have been modified?

      XCOPY has several options.

      The /M option uses the Archive bit to determine what has been modified and what has not; the Archive bit is set automatically by the OS when a file is modified. XCOPY will clear the bit with the /M option, and copy only the files that have been modified.

      The /D:m-d-y option copies only files changed on or after the specified date. This may be another way to accomplish your task.

      http://www.computerhope.com/xcopyhlp.htm

Viewing 2 reply threads