Solved

How to loop file check in script

Posted on 2014-12-08
6
171 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

856 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