FilePing utility

I don't write technical blog posts very often, but I thought I'd share this handy and very basic utility I wrote. Someone out there might find this useful. (I hope..... Well, as a matter of fact, I actually couldn't care less... hehehe)

Some background first:
I often write little batch programs for various tasks, which sends it's output to a log file.
When I initially implement a batch file which will be used in a production environment, I usually want to monitor the results for a while, to make sure it is robust enough. i.e. I keep an eye on the log file for a period of time and look at the results.

How I do this currently, is to have a Windows Explorer window open at the folder where the log file will be created, and then periodically check the window to see if the file is there. This can be rather difficult to keep track of, and messy if there's a bunch of other files cluttering the same folder.

For these reasons, every time I wanted to "continually check if a file exists" (If you are familiar with ping in TCP/IP, you'll understand why I called it a File Ping), I would briefly search Google for a utility that does this, not find anything, forget about it and deal with the "Monitor an Explorer window" method instead.

Anyways... to get back to the point...

This morning, when I had the same situation again, I actually thought about the logic behind this for the first time, and realized that this is Very easy to do. (It was never a big enough problem that I had to really think about it a lot)

You can use the fileping utility attached to this post with the following syntax:

fileping

where is the full path to the file you want to monitor. (for paths with spaces, you can enclose the "path in quotes")

an example:

fileping c:\pagefile.sys

It is recommended to save the "Fileping.bat" batch file into your "C:\Windows\System32" location on your PC, as this will ensure it is included in your entire environment path. (...Thus you will be able to execute it from anywhere.)

Here is an example of pinging a file called ~temp.pid on a network location (UNC path)

Download the fileping utility here (Right click the link and select "Save Target as..". Save to your c:\windows\system32 folder.)

The source code to the program is:


@echo off
REM Fileping utility by Jacques Aucamp.
Echo ** Now Pinging %1. Press CTRL-C to exit.**

:TEST
IF EXIST %1 GOTO REPLY
IF NOT EXIST %1 GOTO TIMEOUT

:REPLY
echo Reply from %1 - File exists
Sleep 1
GOTO TEST

:TIMEOUT
echo Request timed out.
Sleep 1
GOTO TEST

(as you can probably see, this is not exactly the most intricate application ever written, but it works like a charm! Very handy!) Laughing out loud

The script can also be used to check for the existence of a drive (like trying to detect when a flash-drive is plugged into the system)
For example:

Hope someone out there can make use of this. Suggestions Welcome! Laughing out loud

AttachmentSize
fileping.bat225 bytes

Post a comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • Images can be added to this post.
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.
Syndicate content