Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to copy zip files from one server to another with a batch file. Problem is, I only need the 4 zip files with the current date and not the other 100 zips. The file names change everyday, so I need a script to just pick up the files with the current date. Can anyone point me in the right direction?

Hi
Not sure about servers, but this help.@echo off
dir | find "%date%" > files.txt
for /f "tokens=1-4 delims= " %%a in (files.txt) do (
echo copy %%d \Destination
)

@Echo Off
For /F "tokens=4 delims=/ " %%n in ('Date /T') Do Set Year=%%n
Set Year=%year:~2%
Set FDate=%date:~4,-4%%year%For /F "tokens=*" %%n in ('Dir ^| Find "%fdate%"') Do Echo %%n >> %temp%\%~n0.tmp
For /F "tokens=4" %%n in ('Find "zip" %temp%\%~n0.tmp') Do Copy \\server\source\%%n \\server\destination
Del %temp%\%~n0.tmp
----This might address issues with 2 character year formats for Windows 2000 and earlier should you use the script in those OS'.

Hi astroraptor ^ dtech10,
interesting stuff.
As ever, the gotcha is that there are probably dozens of date layouts. Many will use - or : instead of /. Not to mention the YMD order.
I hammered out the script below which gets the system date into these vars:
YYYY
MM
DDI believe it will work with any flavor of 2k/XP and maybe NT4. But NOT DOS.
I welcome any feedback/bug reports. If there is enough interest, I'll work on a comparable DOS solution.
Ther's a copyHere
::== YMD6.bat
:: get sys YMD into vars@echo off
:: YYYY getter
> syyyy.d echo a 100
>> syyyy.d echo mov ah,2a
>> syyyy.d echo int 21
>> syyyy.d echo.
>> syyyy.d echo p=100 2
>> syyyy.d echo n sizeYYYY
>> syyyy.d echo w
>> syyyy.d echo q
debug < syyyy.d > nul
:: OK:: MM getter
> sMM.d echo a 100
>> sMM.d echo mov ah,2a
>> sMM.d echo int 21
>> sMM.d echo mov cx,0
>> sMM.d echo mov cl,dh
>> sMM.d echo.
>> sMM.d echo p=100 4
>> sMM.d echo n sizeMM
>> sMM.d echo w
>> sMM.d echo q
debug < sMM.d > nul
:: OK:: DD getter
> sDD.d echo a 100
>> sDD.d echo mov ah,2a
>> sDD.d echo int 21
>> sDD.d echo mov cx,0
>> sDD.d echo mov cl,dl
>> sDD.d echo.
>> sDD.d echo p=100 4
>> sDD.d echo n sizeDD
>> sDD.d echo w
>> sDD.d echo q
debug < sDD.d > nul
:: OK
del *.dfor %%F in (sizeYYYY sizeMM sizeDD) do call :sub1 %%F
set /p YYYY=<sizeYYYY.#
set /p MM=<sizeMM.#
if %MM% LSS 10 set MM=0%MM%
set /p DD=<sizeDD.#
if %DD% LSS 10 set DD=0%DD%
del size*.*
echo YYYYMMDD=%YYYY%%MM%%DD%
goto :eof:sub1
> %1.# echo %~z1
goto :eof
:: DONE
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |