Dear Laurent Jumet:
From the text of your message and from the code I assume you want to keep
only a single file of a specific size AND extension. What you do not specify
is the command processor version you want to use. Let me suggest the
following comments, regardless of the command processor:
1/ The reason your program deletes only one file of matching size is that
@findnext[] is not repeated after a match to find the next match. But what
is strange is that there is no wildcard in the parameter to @findfirst[], so
@findnext should never find a second match.
2/ Since you do not include @findclose[], you may run out of memory when
there are too many files.
3/ Since the size of each file is stored in the same block on disk as its
name, you can get much better performance from using DIR to obtain both name
and size. If using TCC, or a version of 4NT which supports the PDIR command,
you could retrieve just size and name to a temporary file.
4/ Your original program does not work for files whose name must be quoted
(embedded space or other special characters). I did not try to improve on
that issue.
An alternate program is below. UNTESTED!!! To the best of my knowledge it
ought to work in 4DOS as well as 4NT and TCC.
@echo off
:: report absent work directory and quit
iff not ISDIR H:\prov then
PAUSE Le dossier n'existe pas...
QUIT
endiff
:: make directories and variables etc. local
setlocal
:: create a file for temporary data
set x=%@unique[%temp]
:: ensure the temporary data file is erased on abnormal exit
on error goto CLEANUP
on break goto CLEANUP
:: go to work directory (ENDLOCAL restores original directory)
cdd H:\prov
:: repeat work for all file name extensions of interest
do ext in /l flv mp4 wmv avi
:: save date, time, size and name of each file of specific extension
:: ordered by filesize in temporary file
dir /os *.ext >! %x
:: initialize auxiliary variable
set oldsize=-1
:: cycle through all lines of temporary file
do new in @%x
:: size is word 2 in DIR output record
set newsize=%@word[2,%new]
:: check if current record is for a file of same size as a previous one
iff %newsize EQ %oldsize then
:: same size, new file deleted
del %@word[-0,%new]
else
:: different size, reference size updated
set oldsize=%newsize
endiff
enddo
enddo
:CLEANUP
:: delete temporary file
del %x
--
HTH, Steve
:: implied ENDLOCAL - restores original directory
PS: