Script que utiliza fechas

04/06/2009 - 09:19 por Uyyy | Informe spam
Hola.
Tengo este script 1 que copia los ficheros que empiezan por dife de la
unidad f a la unidad g, pero estoy intentando que copie los ficheros que
dentro del nombre tengan la fecha del dia anterior (script 2)
Script 1
for /f "usebackq tokens=1,2,3 delims=/" %%i IN (`DATE /T`) do set
tmpfecha=%%k%%j%%i
for /f "usebackq tokens=1,2,3 delims= " %%i in (`echo %tmpfecha%`) do set
mifecha=%%i%%k%%j

C:\WINDOWS\system32obocopy F:\ G:\ Dife*.*

Script 2
for /f "usebackq tokens=1,2,3 delims=/" %%i IN (`DATE /T`) do set
tmpfecha=%%k%%j%%i
for /f "usebackq tokens=1,2,3 delims= " %%i in (`echo %tmpfecha%`) do set
mifecha=%%i%%k%%j
set cont=1
set /a mifecha2=%mifecha%-%cont%
C:\WINDOWS\system32obocopy F:\ G:\ Dife*%mifecha2%.*

Esto resta un dia a mifecha, pero claro si el dia que aparece en mifecha es
20090601 el resultado de mifecha2 sera 20090600 en lugar de 20090531. Por
supuesto ni hablar del mes de febrero.

Alguien conoce algun script que controle esto o como hacerlo ?
Gracias.

Preguntas similare

Leer las respuestas

#1 pixilated
04/06/2009 - 12:23 | Informe spam
te mando este script

@ECHO OFF
:: Windows NT 4 or later only
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: No command line arguments required
IF NOT [%1]==[] GOTO Syntax

:: Keep variables local
SETLOCAL

:: Export registry's date format settings to a temporary file
START /W REGEDIT /E %TEMP%.\_TEMP.REG "HKEY_CURRENT_USER\Control
Panel\International"

:: Read the exported data
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I
"iDate"') DO SET iDate=%%B
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I
"sDate"') DO SET sDate=%%B
DEL %TEMP%.\_TEMP.REG

:: Remove quotes from exported values
SET iDate=%iDate:"=%
SET sDate=%sDate:"=%

:: Parse today's date depending on registry's local date format settings
IF %iDate%==0 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormat=MM%sDate%DD%sDate%YYYY
SET YesterLocal=%%YesterM%%%sDate%%%YesterD%%%sDate%%%YesterY%%
SET Year=%%C
SET Month=%%A
SET Day=%%B
)
IF %iDate%==1 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormatÝ%sDate%MM%sDate%YYYY
SET YesterLocal=%%YesterD%%%sDate%%%YesterM%%%sDate%%%YesterY%%
SET Year=%%C
SET Month=%%B
SET Day=%%A
)
IF %iDate%==2 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormat=YYYY%sDate%MM%sDate%DD
SET YesterLocal=%%YesterY%%%sDate%%%YesterM%%%sDate%%%YesterD%%
SET Year=%%A
SET Month=%%B
SET Day=%%C
)

:: Remove the day of week if applicable
FOR %%A IN (%Year%) DO SET Year=%%A
FOR %%A IN (%Month%) DO SET Month=%%A
FOR %%A IN (%Day%) DO SET Day=%%A

:: Today's date in YYYYMMDD format
SET SortDate=%Year%%Month%%Day%

:: Today's date in local format
FOR %%A IN (%Date%) DO SET Today=%%A

:: Strip leading zero from Day
SET DayS=%Day%
IF %Day:~0,1%==0 SET DayS=%Day:~1%

:: Calculate yesterday's date
IF %DayS% EQU 1 (
SET YesterY=%Year%
CALL :RollMonth
) ELSE (
SET /A YesterD=%DayS% - 1
SET YesterM=%Month%
SET YesterY=%Year%
)

:: Add leading zero to YesterD if necessary
IF %YesterD% LSS 10 SET YesterD=0%YesterD%

:: Yesterday's date in YYYYMMDD format
SET SortYest=%YesterY%%YesterM%%YesterD%

:: Display the results
ECHO Format: YYYYMMDD (%LocalFormat%)
ECHO.==ìHO Today: %SortDate% (%Today%)
CALL ECHO Yesterday: %SortYest% (%YesterLocal%)

:: Done
c:
dir /s | find /I "ocx" > C:\personal\temp\ocx\lisdir-%SortDate%.txt
fc C:\personal\temp\ocx\lisdir-%SortDate%.txt
C:\personal\temp\ocx\lisdir-%SortYest%.txt >
C:\personal\temp\ocx\lisdir-dif.txt
ENDLOCAL
GOTO:EOF

:: * * * * * * * * Subroutines * * * * * * * *


:: Subroutine to get yesterday's date if today is the first day of the month
:: Thanks for Aaron M. Jones who pointed out an error in the YesterD value
for Month 2
:RollMonth
IF %Month%= (
SET YesterD1
SET YesterM
SET /A YesterY = %Year% - 1
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD(
SET YesterM
CALL :LeapYear
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
GOTO:EOF


:LeapYear
:: Subroutine to calculate if this year is a leap year, by Anthony Walters
:: Pseudocode from http://en.wikipedia.org/wiki/Leap_year:
:: if year modulo 400 is 0 then leap
:: else if year modulo 100 is 0 then no_leap
:: else if year modulo 4 is 0 then leap
:: else no_leap

SET /A mod400 = %Year% %% 400
SET /A mod100 = %Year% %% 100
SET /A mod4 = %Year% %% 4
IF %mod400% EQU 0 (
SET YesterD)
) ELSE (
IF %mod100% EQU 0 (
SET YesterD(
) ELSE (
IF %mod4% EQU 0 (
SET YesterD)
) ELSE (
SET YesterD(
)
)
)
GOTO:EOF



:Syntax
ECHO.
ECHO Yesterday.bat, Version 2.05 for Windows NT 4 / 2000 / XP
ECHO Display today's and yesterday's date in sorted and local format
ECHO.
IF "%OS%"=="Windows_NT" ECHO Usage: %~n0
IF NOT "%OS%"=="Windows_NT" ECHO Usage: %0
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Adapted for Windows XP with help from Kailash Chanduka
ECHO Local date code by Frederic Guigand and Rob van der Woude
ECHO Improved leapyear subroutine by Anthony Walters

"Por muchos idiomas que se dominen, cuando uno se corta al afeitarse,
siempre se utiliza la lengua materna"

(Eddie Constantine, actor estadounidense)




"Uyyy" wrote:

Hola.
Tengo este script 1 que copia los ficheros que empiezan por dife de la
unidad f a la unidad g, pero estoy intentando que copie los ficheros que
dentro del nombre tengan la fecha del dia anterior (script 2)
Script 1
for /f "usebackq tokens=1,2,3 delims=/" %%i IN (`DATE /T`) do set
tmpfecha=%%k%%j%%i
for /f "usebackq tokens=1,2,3 delims= " %%i in (`echo %tmpfecha%`) do set
mifecha=%%i%%k%%j

C:\WINDOWS\system32obocopy F:\ G:\ Dife*.*

Script 2
for /f "usebackq tokens=1,2,3 delims=/" %%i IN (`DATE /T`) do set
tmpfecha=%%k%%j%%i
for /f "usebackq tokens=1,2,3 delims= " %%i in (`echo %tmpfecha%`) do set
mifecha=%%i%%k%%j
set cont=1
set /a mifecha2=%mifecha%-%cont%
C:\WINDOWS\system32obocopy F:\ G:\ Dife*%mifecha2%.*

Esto resta un dia a mifecha, pero claro si el dia que aparece en mifecha es
20090601 el resultado de mifecha2 sera 20090600 en lugar de 20090531. Por
supuesto ni hablar del mes de febrero.

Alguien conoce algun script que controle esto o como hacerlo ?
Gracias.

Respuesta Responder a este mensaje
#2 Uyyy
04/06/2009 - 13:46 | Informe spam
No funciona en windows 2003 server. Da errores


"pixilated" escribió en el mensaje de
noticias news:
te mando este script

@ECHO OFF
:: Windows NT 4 or later only
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: No command line arguments required
IF NOT [%1]==[] GOTO Syntax

:: Keep variables local
SETLOCAL

:: Export registry's date format settings to a temporary file
START /W REGEDIT /E %TEMP%.\_TEMP.REG "HKEY_CURRENT_USER\Control
Panel\International"

:: Read the exported data
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I
"iDate"') DO SET iDate=%%B
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I
"sDate"') DO SET sDate=%%B
DEL %TEMP%.\_TEMP.REG

:: Remove quotes from exported values
SET iDate=%iDate:"=%
SET sDate=%sDate:"=%

:: Parse today's date depending on registry's local date format settings
IF %iDate%==0 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormat=MM%sDate%DD%sDate%YYYY
SET YesterLocal=%%YesterM%%%sDate%%%YesterD%%%sDate%%%YesterY%%
SET Year=%%C
SET Month=%%A
SET Day=%%B
)
IF %iDate%==1 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormatÝ%sDate%MM%sDate%YYYY
SET YesterLocal=%%YesterD%%%sDate%%%YesterM%%%sDate%%%YesterY%%
SET Year=%%C
SET Month=%%B
SET Day=%%A
)
IF %iDate%==2 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormat=YYYY%sDate%MM%sDate%DD
SET YesterLocal=%%YesterY%%%sDate%%%YesterM%%%sDate%%%YesterD%%
SET Year=%%A
SET Month=%%B
SET Day=%%C
)

:: Remove the day of week if applicable
FOR %%A IN (%Year%) DO SET Year=%%A
FOR %%A IN (%Month%) DO SET Month=%%A
FOR %%A IN (%Day%) DO SET Day=%%A

:: Today's date in YYYYMMDD format
SET SortDate=%Year%%Month%%Day%

:: Today's date in local format
FOR %%A IN (%Date%) DO SET Today=%%A

:: Strip leading zero from Day
SET DayS=%Day%
IF %Day:~0,1%==0 SET DayS=%Day:~1%

:: Calculate yesterday's date
IF %DayS% EQU 1 (
SET YesterY=%Year%
CALL :RollMonth
) ELSE (
SET /A YesterD=%DayS% - 1
SET YesterM=%Month%
SET YesterY=%Year%
)

:: Add leading zero to YesterD if necessary
IF %YesterD% LSS 10 SET YesterD=0%YesterD%

:: Yesterday's date in YYYYMMDD format
SET SortYest=%YesterY%%YesterM%%YesterD%

:: Display the results
ECHO Format: YYYYMMDD (%LocalFormat%)
ECHO.> ECHO Today: %SortDate% (%Today%)
CALL ECHO Yesterday: %SortYest% (%YesterLocal%)

:: Done
c:
dir /s | find /I "ocx" > C:\personal\temp\ocx\lisdir-%SortDate%.txt
fc C:\personal\temp\ocx\lisdir-%SortDate%.txt
C:\personal\temp\ocx\lisdir-%SortYest%.txt >
C:\personal\temp\ocx\lisdir-dif.txt
ENDLOCAL
GOTO:EOF

:: * * * * * * * * Subroutines * * * * * * * *


:: Subroutine to get yesterday's date if today is the first day of the
month
:: Thanks for Aaron M. Jones who pointed out an error in the YesterD value
for Month 2
:RollMonth
IF %Month%= (
SET YesterD1
SET YesterM
SET /A YesterY = %Year% - 1
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD(
SET YesterM
CALL :LeapYear
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
IF %Month%= (
SET YesterD1
SET YesterM
)
IF %Month%= (
SET YesterD0
SET YesterM
)
GOTO:EOF


:LeapYear
:: Subroutine to calculate if this year is a leap year, by Anthony Walters
:: Pseudocode from http://en.wikipedia.org/wiki/Leap_year:
:: if year modulo 400 is 0 then leap
:: else if year modulo 100 is 0 then no_leap
:: else if year modulo 4 is 0 then leap
:: else no_leap

SET /A mod400 = %Year% %% 400
SET /A mod100 = %Year% %% 100
SET /A mod4 = %Year% %% 4
IF %mod400% EQU 0 (
SET YesterD)
) ELSE (
IF %mod100% EQU 0 (
SET YesterD(
) ELSE (
IF %mod4% EQU 0 (
SET YesterD)
) ELSE (
SET YesterD(
)
)
)
GOTO:EOF



:Syntax
ECHO.
ECHO Yesterday.bat, Version 2.05 for Windows NT 4 / 2000 / XP
ECHO Display today's and yesterday's date in sorted and local format
ECHO.
IF "%OS%"=="Windows_NT" ECHO Usage: %~n0
IF NOT "%OS%"=="Windows_NT" ECHO Usage: %0
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Adapted for Windows XP with help from Kailash Chanduka
ECHO Local date code by Frederic Guigand and Rob van der Woude
ECHO Improved leapyear subroutine by Anthony Walters

"Por muchos idiomas que se dominen, cuando uno se corta al afeitarse,
siempre se utiliza la lengua materna"

(Eddie Constantine, actor estadounidense)




"Uyyy" wrote:

Hola.
Tengo este script 1 que copia los ficheros que empiezan por dife de la
unidad f a la unidad g, pero estoy intentando que copie los ficheros que
dentro del nombre tengan la fecha del dia anterior (script 2)
Script 1
for /f "usebackq tokens=1,2,3 delims=/" %%i IN (`DATE /T`) do set
tmpfecha=%%k%%j%%i
for /f "usebackq tokens=1,2,3 delims= " %%i in (`echo %tmpfecha%`) do set
mifecha=%%i%%k%%j

C:\WINDOWS\system32obocopy F:\ G:\ Dife*.*

Script 2
for /f "usebackq tokens=1,2,3 delims=/" %%i IN (`DATE /T`) do set
tmpfecha=%%k%%j%%i
for /f "usebackq tokens=1,2,3 delims= " %%i in (`echo %tmpfecha%`) do set
mifecha=%%i%%k%%j
set cont=1
set /a mifecha2=%mifecha%-%cont%
C:\WINDOWS\system32obocopy F:\ G:\ Dife*%mifecha2%.*

Esto resta un dia a mifecha, pero claro si el dia que aparece en mifecha
es
20090601 el resultado de mifecha2 sera 20090600 en lugar de 20090531. Por
supuesto ni hablar del mes de febrero.

Alguien conoce algun script que controle esto o como hacerlo ?
Gracias.




email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida