PC Review


Reply
Thread Tools Rate Thread

cmd dir info

 
 
Tem
Guest
Posts: n/a
 
      11th Oct 2007
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?


 
Reply With Quote
 
 
 
 
billious
Guest
Posts: n/a
 
      11th Oct 2007

"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....



 
Reply With Quote
 
Tem
Guest
Posts: n/a
 
      12th Oct 2007
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

"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....
>
>
>


 
Reply With Quote
 
Dean Wells \(MVP\)
Guest
Posts: n/a
 
      12th Oct 2007
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" <(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?
>
>



 
Reply With Quote
 
Dean Wells \(MVP\)
Guest
Posts: n/a
 
      12th Oct 2007
.... regarding your follow-up question, simply add ">logfile.txt" to the
end of the command, for example, if you named the batch file
"find1dir.cmd", you would run -

C:\Windows>find1dir >\output.log

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


"Dean Wells (MVP)" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(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?
>>
>>

>
>



 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      13th Oct 2007
> "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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failure to save info entered in User Info, envelopes & Labels =?Utf-8?B?amltIGxvbmdsZXk=?= Microsoft Word Document Management 1 30th May 2007 08:15 PM
need help w/ macro prompting with info and pasting the info based on user input drgka55 Microsoft Excel Programming 8 28th Aug 2006 06:05 PM
FYI: Simple backup/restore of NTFS ACL, owner info, and auditing info Frank-Peter Schultze Microsoft Windows 2000 CMD Promt 1 12th Mar 2004 12:49 AM
File Information Summary garbled, retaining bad info, how to clear info? Lee C. Microsoft Word New Users 6 20th Oct 2003 08:42 PM
__FW: MS's info on Blaster - lots of info and links. READ IT BEFORE POSTING VManes Windows XP General 0 15th Aug 2003 05:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:43 PM.