id="info"

Question

Locked

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

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"

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Not sure what you're using.

by neilb@uk In reply to create batch file to sele ...

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

Collapse -

This worked nicely

by kanignu In reply to Not sure what you're usin ...

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

Collapse -

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.

Collapse -

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

Collapse -

"Today" or "Not copied since last modified"?

by oldbaritone In reply to create batch file to sele ...

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

Collapse -

The difficulty with /D

by neilb@uk In reply to "Today" or "Not copied si ...

is in automating the process and extracting today's date. Robocopy /Maxage:1 is probably the easiest.

Back to Windows Forum
7 total posts (Page 1 of 1)  

Operating Systems Forums