This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
123} How to test if a file is in a folder or below two or more times?
@echo off & setlocal enableextensions enabledelayedexpansion
set startat_=C:\_M
set filename_=temp48.prn
::
set count_=0
for /f %%f in ('dir /b /s "%startat_%\%filename_%"') do (
set /a count_+=1)
::
echo Found %count_% occurrences of %filename_%
if %count_% GTR 1 (
for /f %%f in ('dir /b /s "%startat_%\%filename_%"') do (
set filename_=
%%~dpnxf
set filedate_=
%%~tf
set filesize_=
%%~zf
set filesize_=
!filesize_:~-10
!
echo
!filedate_
! !filesize_
! !filename_
!))
endlocal & goto :EOF
The output might be e.g.
C:\_D\TEST>cmdfaq
Found 2 occurrences of temp48.prn
29.10.2005 07:35 1705 C:\_M\temp48.prn
29.10.2005 07:35 1705 C:\_M\TEMP\TEMP48.PRN
There is a catch, however.
Since
enabledelayedexpansion
has been applied, the file names with exclamation marks would miss the
exclamation mark
! To circumvent this
dilemma, use a subroutine call instead.
@echo off & setlocal enableextensions
set startat_=C:\_M
set filename_=temp48.prn
::
set count_=0
for /f %%f in ('dir /b /s "%startat_%\%filename_%"') do (
set /a count_+=1)
::
echo Found %count_% occurrences of %filename_%
if %count_% GTR 1 (
for /f %%f in ('
dir /b /s "%startat_%\%filename_%"') do (
call :ShowInfo "%%~ff"))
endlocal & goto :EOF
::
:: =======================================================
:ShowInfo
setlocal enableextensions disabledelayedexpansion
set filename_=%~dpnx1
set filedate_=%~t1
set filesize_= %~z1
set filesize_=%filesize_:~-10%
echo %filedate_% %filesize_% %filename_%
endlocal & goto :EOF