Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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)

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.

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?

Hi Misiu10Try 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

![]() |
![]() |
![]() |

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