> "billious" <(E-Mail Removed)> wrote in message
> news:470d79fd$0$12132$(E-Mail Removed)...
>>
>> "Tem" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
It already searches the subdirectories.
The starting directory can be changed by changing 'c:\106x' to the directory
you wish. Enclose the name in double-quotes if it contains spaces.
For "the directory where the batch file resides", try
"%~dp0"
in place of c:\106x above
OR, to specify a directoryname on the command line, use
"%~1"
in place of c:\106x above
You can execute the batch by placing it in any directory in your "path"
(simply execute the command
PATH
from the prompt.)
If you use batch regularly, you may wish to establish a dedicated directory
for your .bat files and include it in your PATH permanently. Popular names
include C:\bat , c:\batch and c:\belfry.
To output to a file rather than the screen, add
>filename
after the appropriate ECHO keyword
......(echo !ysd!>filename)...
above.
If your filename includes spaces, you'd need to enclose the name in
double-quotes.
Being new to .bat syntax isn't a crime. Top-posting in newsgroups however,
is. Top-posting (replying before the existing message text) is normal for
email. In newsgroups, you're likely to find that persistent top-posting will
lead to your being ignored.
As I said, try the newsgroup alt.msdos.batch.nt where you'll find many
examples and even the occasional FAQ.
|