Package: copy files with specified date only

Using a batch script package, I want to copy the files to a folder with a specific date. I don't want to copy files after the specified date, I just want the files whose modified date is exactly the specified date.

I used XCOPY, but the / D option file copied the files to AND after the specified date. Example:

XCOPY "D:\FOLDER" "V:\FOLDERBIS" /K /R /Y /I /D:05-25-2015 /E

      

This will copy files where the modified date is greater than or equal to 25 2015, and I just want files that have the modified date equal to that specific date.

Also, I cannot use ROBOCOPY. Do you have any ideas?

+3


source to share


2 answers


Maybe you can use forfiles

(Win 7 or higher) if you can't use robocopy

(Win XP and higher):

forfiles /D "2.06.2015" /c "cmd /c if @fdate EQU "02.06.2015" echo @file @fdate"

      



The reason for using this command is because it already parses a date.

+2


source


@echo off

set "_date=20150525"
set "directory=D:\FOLDER"

for %%# in (%directory%) do (
    set "_path=%%~pn#"
    set "_drive=%%~d#"
)


set "_path=%_path:\=\\%\\"

setlocal enableDelayedExpansion

for /f "tokens=* delims=" %%# in ('wmic datafile where "path='%_path%' and drive='%_drive%' " get LastModified^,Caption /Format:value') do (
    for /f "tokens=1,2 delims==" %%A in ("%%#") do (
        if "%%A" equ "Caption" (
            set _fpath=%%B
        )

        if "%%A" equ "LastModified" (
            set _time=%%B
            if  !time:~0,8! equ %_date% (
                echo file !_fpath! has been created on !_time!
                rem :: remove echo if everything is ok
                echo copy "!_fpath!" "V:\FOLDERBIS"
            )
        )
    )

)

      

EDIT : file dates filtered with wmic request



@echo off

set "_date=20150525"
set "directory=D:\FOLDER"


:: time zone is not used to deal better with - and + signs
for /f %%$ in ('wmic os get LastBootUpTime /format:value') do (
    for /f %%# in ("%%$") do set "%%#"
)
set offset=%LastBootUpTime:~21,4%

set "edate=%_date%235959.999999%offset%"
set "bdate=%_date%000000.000000%offset%"

for %%# in (%directory%) do (
    set "_path=%%~pn#"
    set "_drive=%%~d#"
)


set "_path=%_path:\=\\%\\"

for /f "skip=1 tokens=* delims=" %%# in (' wmic datafile where "path='%_path%' and drive='%_drive%'  and LastModified<='%edate%' and LastModified>='%bdate%'" get Caption /Format:table') do (
    for /f "tokens=* delims=" %%A in ("%%#") do (
        echo %%A
        copy "%%A" "V:\FOLDERBIS"
    )

)

      

+1


source







All Articles