I would like to develop a batch file with the following condition:
- Checking the DayOfWeek is whether equal to Mon - Fri --> (True) --> Copy ALL files --> (False) --> Go to check next condition
- Checking the DayOfWeek is whether equal to Sat --> (True) --> Copy certain files --> (False) --> Go to check next condition
- Checking the DayOfWeek is whether equal to Sun or public holiday --> Show an error message and exit
(Remark: My idea is put those date of public holiday store to the text file and get value to check on it.)
@ECHO OFF
FOR /F %%a IN ('Powershell -noP -c "(Get-Date).DayOfWeek.Value__"') DO SET week=%%a
IF %week% == "1" (GOTO ALLFOLDER)
IF %week% == "2" (GOTO ALLFOLDER)
IF %week% == "3" (GOTO ALLFOLDER)
IF %week% == "4" (GOTO ALLFOLDER)
IF %week% == "5" (GOTO ALLFOLDER)
IF %week% == "6" (GOTO CERTAINFOLDER)
IF %week% == "7" (ECHO ERROR! Script Exit!) EXIT(0)
ECHO Copying Files...
TIMEOUT /T 1 /NOBREAK > NUL
ECHO.
COPY C:\A.DAT E:\A.BAT
TIMEOUT /T 1 /NOBREAK > NUL
COPY C:\B.DAT E:\B.BAT
TIMEOUT /T 1 /NOBREAK > NUL
COPY C:\C.DAT E:\C.BAT
TIMEOUT /T 1 /NOBREAK > NUL
COPY C:\D.DAT E:\D.BAT
TIMEOUT /T 1 /NOBREAK > NUL
COPY C:\E.DAT E:\E.BAT
:ALLFOLDER
ECHO Checking Folder....
ECHO.
IF EXIST %A% (
ECHO A Folder Already Exists!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
) ELSE (
MKDIR %A%
ECHO A Folder Created!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
)
IF EXIST %B% (
ECHO B Folder Already Exists!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
) ELSE (
MKDIR %B%
ECHO B Folder Created!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
)
IF EXIST %C% (
ECHO C Folder Already Exists!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
) ELSE (
MKDIR %C%
ECHO C Folder Created!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
)
IF EXIST %D% (
ECHO D Folder Already Exists!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
) ELSE (
MKDIR %D%
ECHO D Folder Created!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
)
IF EXIST %E% (
ECHO E Folder Already Exists!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
) ELSE (
MKDIR %E%
ECHO E Folder Created!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
)
Powershell -noP -c "Write-Host 'INFO: Check Completed!' -ForegroundColor GREEN"
TIMEOUT /T 2 /NOBREAK > NUL
:CERTAINFOLDER
IF EXIST %A% (
ECHO A Folder Already Exists!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
) ELSE (
MKDIR %A%
ECHO A Folder Created!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
)
IF EXIST %B% (
ECHO B Folder Already Exists!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
) ELSE (
MKDIR %B%
ECHO B Folder Created!
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
)
Powershell -noP -c "Write-Host 'INFO: Check Completed!' -ForegroundColor GREEN"
TIMEOUT /T 2 /NOBREAK > NUL
Thanks.
Aucun commentaire:
Enregistrer un commentaire