Computing.Net > Forums > Programming > Compare Files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Compare Files

Reply to Message Icon

Name: Misiu10
Date: June 30, 2009 at 12:09:11 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hello,

I am working in DOS on an XP machine and trying to write a batch script that will read a large list of file names from one text file and output which of them are not present in another.

The overall idea is to have a logging script that lists all the files in a given (current) folder (and all subfolders) and will tell you which of them were not there the last time the script has run.

I am aware that DOS is not the best language to be doing this in, but unfortunatly, this is what I am stuck with for the time being.

Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: June 30, 2009 at 22:37:45 Pacific
Reply:

you can try using GNU grep.
usage:

 c:\> grep -f list file.txt 

GNU win32 packages | Gawk


0

Response Number 2
Name: dtech10
Date: July 1, 2009 at 14:37:18 Pacific
Reply:

Hi Misiu10
Something like this


@echo off
SetLocal EnableDelayedExpansion
set Count=0
rem ------------------------------------
rem My Testing Files, Replace with Yours
dir /b /s "g:\Virus Scanners" >File1.txt
dir /b /s "g:\Virus Scanners" >File2.txt
Rem Create 5 new file in File2,txt
for /L %%a in (1,1,5) do (
echo NewFile%%a.txt>>File2.txt
)
rem -------------------------------------

:Again
for /f "tokens=* delims=" %%a in (File1.txt) do (
set Flag=0
set NotFound=
for /f "tokens=* delims=" %%b in (File2.txt) do (
if "%%a"=="%%b" (
set Flag=1
set NotFound=
)
if !Flag!==0 (set NotFound=%%a)
)
if Not "!NotFound!"=="" (echo !NotFound!)
)
ren File1.txt ~.txt
ren File2.txt File1.txt
ren ~.txt File2.txt
set /a Count+=1
if %Count% LSS 2 (goto Again)


0

Response Number 3
Name: Misiu10
Date: July 6, 2009 at 11:06:20 Pacific
Reply:

Thanks to both of you, especially dtech; that was exactly what I was looking for. As for ghostdog, I have done from Linux and was unaware that you could import grep and other suck commands. Thanks for your help guys.


0

Response Number 4
Name: Misiu10
Date: July 6, 2009 at 11:39:06 Pacific
Reply:

Ok, slight snag on the same program. Thanks to dtech I now have a batchfile that searches through a directory, and logs all the files that were changed since the last log was created. The problem is that this includes the log, and the batch file, itself. Is there a simple way I could either delete these files from the log, or prevent them from being included in the comparison?


0

Response Number 5
Name: dtech10
Date: July 6, 2009 at 17:45:58 Pacific
Reply:


Hi Misiu10

Try this, applying it to your dir with the log & batch file in.
This should create File1.txt without the the log.txt & log.bat. Replace with your filenames
ofcourse.

dir /b /s "g:\YourDir" | find /v "log.txt" | find /v "log.bat" > File1.txt




0

Related Posts

See More



Response Number 6
Name: Misiu10
Date: July 7, 2009 at 06:01:02 Pacific
Reply:

Thanks Dtech,

Once again, you've hit the nail on the head.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Compare Files

Dos Batch to compare file times www.computing.net/answers/programming/dos-batch-to-compare-file-times/17476.html

Compare files with AWK www.computing.net/answers/programming/compare-files-with-awk/15182.html

Comparing Files+Folders using VBS www.computing.net/answers/programming/comparing-filesfolders-using-vbs/14112.html