Solved

How to loop file check in script

Posted on 2014-12-08
6
168 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 83

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 83

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Remote Assistance 5 20
Win 7 - Devices and Printers folder doesn't populate 10 23
Runtime Error 2 28
Malware Exploit 5 78
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

911 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

18 Experts available now in Live!

Get 1:1 Help Now