Solved

How to loop file check in script

Posted on 2014-12-08
6
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 84

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
To Patch or not to Patch? That is the question!

Don't get caught out like thousands of others around the world in the recent Ransomware Fiasco!
Discuss..
- Why it's not a good idea to wait before Patching
- Sensible approaches to Patching discussed
- Add your feedback, comments and suggestions

 
LVL 84

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

710 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