Solved

How to loop file check in script

Posted on 2014-12-08
6
172 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…

763 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