find 2txt files and compare with fc

April 7, 2009 at 03:22:30
Specs: Windows 2000 sp4
HI, I'm trying to write a W2K batch file on a test rig to find filenames including the string 'exenames', dated yesterday and today, comparing both files with FC. I cannot work out how to construct an IF or FOR to iteratively pop each filename into a variable, then send both as vars say %file1%, %file2% to FC. Anyone tried this before?

See More: find 2txt files and compare with fc

Report •


#1
April 7, 2009 at 03:34:51
I think I can script the vars, but "date math" is always the deal-killer".


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
April 7, 2009 at 03:43:48
Thanks for the response. So...what about just finding and saving each matching filename in two vars, ignoring dates? I can pass em as %var% to FC at least. I'm only just starting this batch stuff and must admit its got me stumped

Report •

#3
April 7, 2009 at 04:58:49
If there are just 2, this should put a dent in it.

==========================
@echo off & setLocal EnableDelayedExpansion

set N=
for /f "tokens=* delims=" %%a in ('dir/s/b/a-d ^| find "exenames"') do (
set /a N+=1
set v!N!=%%a
)

fc !v1! !v2!


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
April 7, 2009 at 05:20:59
Hey thanks a lot, thats just what I need! The solution is interesting, could you elaborate on this section:
set /a N+=1
set v!N!=%%a

-I'm assuming N in this context is a placeholder for an unspecified number (initially 0 then incremented by 1 each time the loop iterates) used as part of the var name? I don't see this in the docs for FOR, SET, etc, any good books you'd recommend?
I guess the only way to further refine for dates going forward, is if each file found was renamed with todays %DATE% in the filename...is there no other way around it due to DIRs reduced output with /b?


Report •

#5
April 7, 2009 at 05:49:39
ah, a problem, I got a:

FC: Invalid Switch

FC: cannot open C:\DOCUMENTS - No such file or folder

-I was sure it would work too(This is running within C:\Documents and Settings\%username% btw) I *think* the v1 var is being populated with the directory location banner one sees on the command line up to the first ' ' (space)...instead of the first filename of the two present. So FC cannot compare C:\Documents and exenames234.txt as this is nonsensical. Is there a way to subtract out the location banner above DIR/FIND output?


Report •

#6
April 8, 2009 at 03:53:30
[1] You got the N thing figured out.

[2] Don't know of any books.

[3] Although date math is a can of worms, we can easily find the 2 most recent.

[4] The path with spaces can be accomodated. Change this:


fc !v1! !v2!

to this:


fc "!v1!" "!v2!"


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#7
April 8, 2009 at 04:13:04
Gad! So simple. It works but I get an error "Resync Failed. Files are too different." so I'm gonna google this...thanks!

Report •

#8
April 8, 2009 at 04:30:59
Got it, I just had a bad input file (one of the exenames text files had duplicate content: i recreated it today, and deleted the bloated one from yesterday)

thanks very much for all your effort Mechanix2Go!


Report •


Ask Question