How to detect if at least one file in a directory (sub) tree has changed ?

P

Paul Barasoa

I would like to find out if at least one file in a directory (sub) tree has changed (resp. is added/deleted) since
since a certain timestamp in the past.

If I e.g. add a file to a sub-sub-directory only the modified date of the directly enclosing folder changes
but NOT the one of the top-most directory.

So is there another way to find it out. I would prefer to have a simple command line tool for this task.

Paul
 
M

Matthias Tacke

Paul Barasoa wrote:

Hello Paul,
I'm in doubt if heavy crossposting with a followup will make new friends.
I would like to find out if at least one file in a directory (sub)
tree has changed (resp. is added/deleted) since since a certain
timestamp in the past.
To detect the deletion of a file requires either to continually check or
have a stored status.
If I e.g. add a file to a sub-sub-directory only the modified date of
the directly enclosing folder changes but NOT the one of the top-most
directory.
So is there another way to find it out. I would prefer to have a
simple command line tool for this task.
Paul

xcopy /L /S /D:12-31-03 C:\Windows %temp%\dummy

will return a list of changed files since month-day-year in C:\windows
and subfolders. Xcopy syntax needs a destination but no copy takes place
due to /L switch.

Another idea is to create a md5sum of a dir listing, store that checksum
and compare it.

Search for auditing tools via google.

Or use a tool like this freeware program from Frank Westlake:

http://gearbox.maem.umr.edu/batch/f_w_util/Frank_Westlake-Freeware.html

Version 0.511, Copyright (C)2002 Frank P. Westlake
Waits until a folder has changed and notifies which file was changed.

WaitDirChg [options] "Folder name"

[options (case not sensitive)]
/F Print the full file path (default is a relative path).
/L Loop until CTRL-C or CTRL-BREAK.
/S Also watch subdirectories.
/T Print a date and time stamp in the first two columns.
/FILE_NAME Watches for changes to file names (add, del, ren)(default).
/DIR_NAME Watches for changes to directory names (md, rd, ren).
/ATTRIBUTES Watches for changes to file attributes.
/SIZE Watches for changes to file size.
/LAST_WRITE Watches for changes to file last write time.
/LAST_ACCESS Watches for changes to file last access time.
/CREATION Watches for changes to file creation time.
/SECURITY Watches for changes to file security-descriptor.
/ANY Watches for any changes in the folder.

The program exits when the first change is detected and reports only that
change, unless the /L switch is included. If the /L switch is included the
program will return to watching the folder (some changes may be lost between
cycles).

ERRORLEVELS AND MESSAGES:
0=[DATE TIME ]CHANGE_TYPE FILE 1=(Program error, message varies)
2=ERROR: CTRL-C 3=ERROR: CTRL-BREAK 4=ERROR: CONSOLE CLOSED
5=ERROR: LOGOFF 6=ERROR: SHUTDOWN
CHANGE_TYPE:
New_File: The file was added to the directory.
Del_File: The file was removed from the directory.
Mod_File: The file was modified (time stamp or attributes).
Old_Name: The file was renamed and this is the old name.
New_Name: The file was renamed and this is the new name.

SCRIPT EXAMPLE:
:LOOP
For /F "tokens=1* delims=: " %%a in ('WaitDirChg/fs %FTP_IN% 2^>^&1') Do (
Set Type=%%a
Set File=%%b
)
If "%File:~0,5%"=="ERROR" Goto :EOF
If "%Type%"=="Watching" Goto :LOOP
If "%Type%"=="New_File" ECHO.New: %File%
If "%Type%"=="Del_File" ECHO.Deleted: %File%
If "%Type%"=="Mod_File" ECHO.Modified: %File%
If "%Type%"=="Old_Name" ECHO.Renamed from: %File%
If "%Type%"=="New_Name" ECHO.Renamed to: %File%
GOTO :LOOP
======================================================================

HTH
 
F

frodo

Yes, a batch file or win script could do this. you'd have to learn them
tho. As a teaser, look at what the DIR command can do, its /T /S and /O
options could let you get a sorted file list by last-modified-date.

Perhaps a more powerful file manager tool would suite you. Check out
ZTree. I couldn't live without it, extreamly powerful and useful, but
like all powerful tools (as Norm says) "read, understand, and follow all
instructions to avoid injury".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top