Solved

How to loop file check in script

Posted on 2014-12-08
6
165 Views
Last Modified: 2014-12-08
Here is the script I've got that checks for files in a particular directory.  It's great but it runs the first check and then stops.  It doesn't keep checking for files.  How do I modify this?

@echo off
setlocal

set /p "Computer=Please enter computer name: "
if "%Computer%" EQU "" (
  echo No computer name entered, ending.
  exit /b
)

set logfile= \\__\public\FG_Diagnostic\%computer%.log


if exist "\\%computer%\c$\program files\formsgen\isep.bbs" (
    echo file [isep.bbs] exists> %logfile%
) else (
    echo file [isep.bbs] doesn't exist> %logfile%
)

if exist "\\%computer%\c$\program files\formsgen\3270.pad" (
    echo file [3270.pad] exists> %logfile%
) else (
    echo file [3270.pad] doesn't exist> %logfile%
)

if exist "\\%computer%\c$\program files\formsgen\3270_18.bmp" (
    echo file [3270_18.bmp] exists> %logfile%
) else (
    echo file [3270_18.bmp] doesn't exist> %logfile%
)

Open in new window


Thanks for your help!
0
Comment
Question by:samiam41
  • 4
  • 2
6 Comments
 
LVL 82

Expert Comment

by:oBdA
ID: 40487230
You didn't say what exactly it is that you want to do; continue looking for files until one is missing, or until all are there.
You didn't say either what to do when whatever the script is waiting for is happening.
So for starters, here's a script that waits until all three files are found:
@echo off
setlocal
set FileList="isep.bbs", "3270.pad", "3270_18.bmp"

set /p "Computer=Please enter computer name: "
if "%Computer%" EQU "" (
  echo No computer name entered, ending.
  exit /b
)

set logfile= \\__\public\FG_Diagnostic\%computer%.log

if exist "%LogFile%" del "%LogFile%"
:Loop
set AllFilesFound=True
for %%a in (%FileList%) do (
	if exist "\\%computer%\c$\program files\formsgen\%%~a" (
		>>"%logfile%" echo [%Date%][%Time%] file [%%~a] exists.
	) else (
		>>"%logfile%" echo [%Date%][%Time%] file [%%~a] doesn't exist.
		set AllFilesFound=False
	)
)
if /i "%AllFilesFound%"=="False" (
	>>"%logfile%" echo At least one file is missing, waiting 5 seconds before the next check.
	ping.exe -n 6 localhost >NUL
	goto Loop
)
>>"%logfile%" echo All files accounted for.

Open in new window

0
 
LVL 9

Author Comment

by:samiam41
ID: 40487233
Hi oBdA!  Good to work with you again.

I actually want to check the directory for several files and report back if they are there or not.
0
 
LVL 9

Author Comment

by:samiam41
ID: 40487263
ok.  Throwing this out there and you tell me if this is an easier option.  

Keep the option for entering in the computer name but change the script so that all of the files in a particular directory are output to a log file?  I will just check the log file and see what isn't listed.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
ID: 40487354
@echo off
setlocal
set Folder=c$\program files\formsgen

set /p "Computer=Please enter computer name: "
if "%Computer%" EQU "" (
  echo No computer name entered, ending.
  exit /b
)
set logfile= \\__\public\FG_Diagnostic\%computer%.log

>"%logfile%" echo Files in '%Folder%' as of %Date% %Time%:
dir /b /o:n /a:-d "\\%computer%\%Folder%\*.*" >>"%logfile%"

Open in new window

0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 40487382
Great work as always!
0
 
LVL 9

Author Comment

by:samiam41
ID: 40487402
oBdA, if you have a chance, could you please check into this?

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28576542.html

I would appreciate it.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now