T
Tem
I need help writing a script that prints the path of directories that
contains only 1 file.
can this be done with a bat script?
contains only 1 file.
can this be done with a bat script?
Tem said:I need help writing a script that prints the path of directories that
contains only 1 file.
can this be done with a bat script?
billious said:Tem said:I need help writing a script that prints the path of directories that
contains only 1 file.
can this be done with a bat script?
Perhaps you should try alt.msdos.batch.nt
----- batch begins -------
[1]@echo off
[2]setlocal enabledelayedexpansion
[3]for /f "tokens=*" %%a in ( ' dir /s c:\106x ^|findstr /i /c:":\\" /c:"
1 file(s)" ' ) do echo %%a|find ":" >nul&if errorlevel 1 (echo !ysd!) else
(for /f "tokens=2*" %%i in ("%%a") do set ysd=%%j)
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped
and should be rejoined. The [number] that starts the line should be
removed
The spaces surrounding the single-quotes are for emphasis only. The SPACES
are not required but the single-quotes ARE required.
C:\106x... is my test directory. Modify to suit your relative-root.
%varname% will be evaluated as the value of VARNAME at the time that the
line is PARSED. The ENABLEDELAYEDEXPANSION option to SETLOCAL causes
!varname! to be evaluated as the CURRENT value of VARNAME - that is, as
modified by the operation of the FOR
The above will generate erroneous results for directory names that contain
certain punctuation characters with special meaning to batch, such as "&"
but will be fine for names containing only alphas, numerics, spaces $_#@
etc. This could be solved if required....
Dean Wells (MVP) said:The following will do as you ask -
[BEGIN]
@for /f "tokens=*" %%d in ('dir /ad/s/b') do @dir "%%d" 2^>nul | find
"1 File(s)" >nul && @echo %%d
[/END]
... paste the text between [begin] and [end] above into a batch file
(note that it's a single line, manually remove any line breaks) and
run the batch file from the directory you wish to begin the search at.
--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
Tem said:I need help writing a script that prints the path of directories that
contains only 1 file.
can this be done with a bat script?
billious said:Tem said:I need help writing a script that prints the path of directories that
contains only 1 file.
can this be done with a bat script?
Perhaps you should try alt.msdos.batch.nt
----- batch begins -------
[1]@echo off
[2]setlocal enabledelayedexpansion
[3]for /f "tokens=*" %%a in ( ' dir /s c:\106x ^|findstr /i /c:":\\" /c:"
1 file(s)" ' ) do echo %%a|find ":" >nul&if errorlevel 1 (echo !ysd!)
else (for /f "tokens=2*" %%i in ("%%a") do set ysd=%%j)
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped
and should be rejoined. The [number] that starts the line should be
removed
The spaces surrounding the single-quotes are for emphasis only. The
SPACES are not required but the single-quotes ARE required.
C:\106x... is my test directory. Modify to suit your relative-root.
%varname% will be evaluated as the value of VARNAME at the time that the
line is PARSED. The ENABLEDELAYEDEXPANSION option to SETLOCAL causes
!varname! to be evaluated as the CURRENT value of VARNAME - that is, as
modified by the operation of the FOR
The above will generate erroneous results for directory names that
contain certain punctuation characters with special meaning to batch,
such as "&" but will be fine for names containing only alphas, numerics,
spaces $_#@ etc. This could be solved if required....
Tem said:Thank you for your help.
How can I modify the script so that it searches the dir and sub dirs it
resides in. and also export the path of folders with only 1 file to a text
file?
I'm new to bat script syntax
filename