65.9K
CodeProject is changing. Read more.
Home

C++ Win32 Command Line Tail - Made Easy

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.95/5 (13 votes)

Apr 3, 2006

viewsIcon

41093

downloadIcon

879

Tail Program - Similar to unix tail - I found tail programs - but not a good CUI project. It runs continuously and prints the last characters as soon as the file gets updated. Coding is very easy - and one can reuse and move further with it

Sample Image - Tail.jpg

Introduction

This is a command line tail program which prints the last updated characters of a file. One can use this to view the log files.

This program keeps on running and as soon as the file gets updated, the last characters are shown.

Usage

Tail [Absolute File Path]

Example:

tail c:\demo.txt
Above command shows the last characters of the file as soon as it is updated and waits again for the file to be updated

About The Code

Code is very simple - still some notes on it.

  • getftime - Small function to get the File Timestamp in character array.
  • getfnoc - Returns number of characters of a file
  • Logic: First I opened the file, got its timestamp and total characters present. Next in a loop - with sleep delay, i am checking the timestamp with initial one, and if there is diffrence, just printing the added characters and updating the variable for total characters. Thats All. Very Easy.