we have a scheduler called TIDAL Enterprise Scheduler a software that we use to schedule a job. the scheduler runs a windows copy command to copy a file however the job failed when it does not find a file. to avoid this a batch file is a workaround to check if the file exist and if not return a friendly message that tells the file is not found.
i am attempting to write a batch file that will accepts two input parameters. the first parameter is to tell what files is to be copied, and the second parameter is to tell where the files are to be copied.
basically here is what i have so far:
@echo off
rem parameter settings
set pInputFile=%1%
set pOutputFile=%2%
set vDate=%date%
rem display system info
ver
echo Current sysdate date: %vDate%
rem display the source folder listing
echo Source folder listing
echo.
cd %~p1
dir %~p1
echo.
echo looking for the file %pInputFile%
echo.
for %%a in (%pInputFile%) do (
if EXIST %%a (echo %%a was found) ELSE (echo %~nx1 missing))
when i run the batch file with this command:
check_file.bat "e:\apps\ias\travelvouchertst\in\*FPCSFADZ_*.ENC" "e:\apps\ias\travelvouchertst\out"
i got this output:
Microsoft Windows [Version 5.2.3790]
Current sysdate date: Mon 04/12/2010
Source folder listing
Volume in drive E is Data
Volume Serial Number is 02EC-D431
Directory of E:\APPS\IAS\travelvouchertst\in
04/02/2010 12:05 PM <DIR> .
04/02/2010 12:05 PM <DIR> ..
04/08/2010 11:50 AM 883,908 1FPCSFADZ_sample01.ENC
03/23/2010 12:00 PM 155,832 1FPCSFAEA_sample01.ENC
04/08/2010 11:50 AM 1,008,522 2FPCSFADZ_sample02.ENC
04/08/2010 11:50 AM 860,688 3FPCSFADZ_sample03.ENC
04/08/2010 11:50 AM 873,330 4FPCSFADZ_sample04.ENC
03/23/2010 03:21 PM 0 ExpenseAnywhereTempFile.null
03/23/2010 04:15 PM 1,008,522 FPCSFADZ_20100323_051747.ENC
03/24/2010 05:20 AM 860,688 FPCSFADZ_20100324_051835.ENC
03/25/2010 04:18 AM 873,330 FPCSFADZ_20100325_041614.ENC
03/26/2010 05:25 AM 883,908 FPCSFADZ_20100326_052315.ENC
03/23/2010 12:00 PM 155,832 FPCSFAEA_20100323_091554.ENC
11 File(s) 7,564,560 bytes
2 Dir(s) 9,253,732,352 bytes free
looking for the file "e:\apps\ias\travelvouchertst\in\*FPCSFADZ_*.ENC"
1FPCSFADZ_sample01.ENC missing
Completed at 4/12/2010 11:36 AM
the files are existing and if i try to replace this line of code:
for %%a in (%pInputFile%) do (
with this actual file it works:
for %%a in (*FPCSFADZ_*.ENC) do (
Microsoft Windows [Version 5.2.3790]
Current sysdate date: Mon 04/12/2010
Source folder listing
Volume in drive E is Data
Volume Serial Number is 02EC-D431
Directory of E:\APPS\IAS\travelvouchertst\in
04/02/2010 12:05 PM <DIR> .
04/02/2010 12:05 PM <DIR> ..
04/08/2010 11:50 AM 883,908 1FPCSFADZ_sample01.ENC
03/23/2010 12:00 PM 155,832 1FPCSFAEA_sample01.ENC
04/08/2010 11:50 AM 1,008,522 2FPCSFADZ_sample02.ENC
04/08/2010 11:50 AM 860,688 3FPCSFADZ_sample03.ENC
04/08/2010 11:50 AM 873,330 4FPCSFADZ_sample04.ENC
03/23/2010 03:21 PM 0 ExpenseAnywhereTempFile.null
03/23/2010 04:15 PM 1,008,522 FPCSFADZ_20100323_051747.ENC
03/24/2010 05:20 AM 860,688 FPCSFADZ_20100324_051835.ENC
03/25/2010 04:18 AM 873,330 FPCSFADZ_20100325_041614.ENC
03/26/2010 05:25 AM 883,908 FPCSFADZ_20100326_052315.ENC
03/23/2010 12:00 PM 155,832 FPCSFAEA_20100323_091554.ENC
11 File(s) 7,564,560 bytes
2 Dir(s) 9,253,732,352 bytes free
looking for the file "e:\apps\ias\travelvouchertst\in\*FPCSFADZ_*.ENC"
1FPCSFADZ_sample01.ENC was found
2FPCSFADZ_sample02.ENC was found
3FPCSFADZ_sample03.ENC was found
4FPCSFADZ_sample04.ENC was found
FPCSFADZ_20100323_051747.ENC was found
FPCSFADZ_20100324_051835.ENC was found
FPCSFADZ_20100325_041614.ENC was found
FPCSFADZ_20100326_052315.ENC was found
Completed at 4/12/2010 11:42 AM
why can't i use a parameter to do a loop? please advise.
thanks,
warren