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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch script to copy current date f

Reply to Message Icon

Name: Jay_DC
Date: March 16, 2006 at 08:20:17 Pacific
OS: Windows XPSP2
CPU/Ram: P4 3.8G
Product: 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?



Sponsored Link
Ads by Google

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

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
)


0

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

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


0

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

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: batch script to copy current date f

Batch sript to copy the folders modified toda www.computing.net/answers/programming/batch-sript-to-copy-the-folders-modified-toda/19369.html

script to copy specify date file to www.computing.net/answers/programming/script-to-copy-specify-date-file-to/17662.html

Batch script to search/copy/replace www.computing.net/answers/programming/batch-script-to-searchcopyreplace/16663.html