Computing.Net > Forums > Programming > batch script to copy current date f

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

batch script to copy current date f

Reply to Message Icon

Original Message
Name: Jay_DC
Date: March 16, 2006 at 08:20:17 Pacific
Subject: batch script to copy current date f
OS: Windows XPSP2
CPU/Ram: P4 3.8G
Model/Manufacturer: DELL
Comment:

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?


Report Offensive Message For Removal


Response Number 1
Name: dtech10
Date: March 16, 2006 at 14:16:39 Pacific
Reply: (edit)

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
)


Report Offensive Follow Up For Removal

Response Number 2
Name: astroraptor
Date: March 21, 2006 at 20:47:37 Pacific
Reply: (edit)

@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'.


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: March 22, 2006 at 03:25:12 Pacific
Reply: (edit)

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
DD

I 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 *.d

for %%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


Report Offensive Follow Up For Removal







Post Locked

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


Go to Programming Forum Home








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 7 Days.
Discuss in The Lounge
Poll History




Data Recovery Software