Applications listing

  • Thread starter Thread starter Justin Fancy
  • Start date Start date
J

Justin Fancy

Hi,

I need a command that will list, in all subdirectories as well, all
Directories that contain a file, for example "sample.txt".

My preferred output would look like this:

wwwroot/aviation/
wwwroot/aviation/CACCRA/
wwwroot/samplefolder/hhyj
wwwroot/samplefolder2/samplesubfolder/samplesubfolder3


If anybody has the correct syntax, could you please send it along.
Thanks.

Justin Fancy
 
Justin Fancy said:
Hi,

I need a command that will list, in all subdirectories as well, all
Directories that contain a file, for example "sample.txt".

My preferred output would look like this:

wwwroot/aviation/
wwwroot/aviation/CACCRA/
wwwroot/samplefolder/hhyj
wwwroot/samplefolder2/samplesubfolder/samplesubfolder3


If anybody has the correct syntax, could you please send it along.
Thanks.

Justin Fancy

Another problem princess? Oh - we are honoured.



----- batch begins -------
[1]@echo off
[2]setlocal enabledelayedexpansion
[3]for /r . %%i in (.) do if exist %%i\sample.txt set ypf=%%~pnxi&echo
!ypf:~1!
[4]for /r . %%i in (.) do if exist %%i\sample.txt set ypf=%%~pnxi&set
ypf=!ypf:~1!&echo !ypf:\=/!
------ 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


%varname% will be evaluated as the value of VARNAME at the time that
the line is PARSED. The ENABLEDELAYEDEXPANSION option to SETLOCAL causes
!varname! tobe evaluated as the CURRENT value of VARNAME - that is, as
modified by the operation of the FOR

Line [3] shows the output with "\"
Line [4] shows the output with "\" converted to "/"

The "." directly following the /r in [3] and [4] is the relative root from
which to scan, "." meaning "current directory" as usual.
 
-----Original Message-----
From: Justin Fancy [mailto:[email protected]]
Posted At: Tuesday, November 21, 2006 5:44 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: Applications listing
Subject: Applications listing

I need a command that will list, in all subdirectories as well, all
Directories that contain a file, for example "sample.txt".

My preferred output would look like this:

wwwroot/aviation/
wwwroot/aviation/CACCRA/
wwwroot/samplefolder/hhyj
wwwroot/samplefolder2/samplesubfolder/samplesubfolder3

In addition to billious's reply, here's another way to accomplish this:

@echo off
set rootdir=c:\mydir
set file=sample.txt
for /f %%i in (
'dir /b /s "%rootdir%\%file%"') do echo %%~dpi
 
I need to search for all "*.asp" files and all "web.config" files that
are in any of the folders and subfolders. Shall I just substitute the
values?
 
Oh and I need some more things if its possible PRINCESS!! hahaha.

I need to display only the unique directory names, but I also need a
count for all the files found in that directory.

Output example:

/wwwroot/justin/isaprincess/;89
/wwwroot/me/no/you/;94

Can it be done!??

J
 
Justin Fancy said:
Oh and I need some more things if its possible PRINCESS!! hahaha.

I don't get it, what's the deal with "PRINCESS" thing? Did I miss something?
I need to display only the unique directory names

With static file names you can just go ahead and substitute file name in my
initial example. For wildcards like *.asp however... that wouldn't quite
work. As you probably already noticed, script will produce one line of
output per file found so in case of folder with multiple asp files you'l see
multiple occurencies of folder name in the output.
, but I also need a count for all the files found in that directory.

Yes, that too can be done. Consider following example which wasn't heavily
tested but worked for me:

@echo off
setlocal enabledelayedexpansion
set rootdir=c:\inetpub\wwwroot
set file=*.asp
set folder=%rootdir%&set n=0
for /f "delims=" %%i in (
'dir /b /s "%rootdir%\%file%"') do (
if "!folder!"=="%%~dpi" (
set /a n+=1
) else (
if !n! GTR 0 echo !folder!^;!n!
set n=1
set folder=%%~dpi
)
)
 
Alex, whoever this guy/girl is calling me "Princess", i just went along
with him/her. haha...

Anyway, the script doesn't seem to work for me?

I'm mapping a network drive and then searching that drive. Here's mine:

@echo off
net use x: \\tc2s03\d$
setlocal enabledelayedexpansion
set rootdir=x:
set file=*.asp
set folder=%rootdir%&set n=0
for /f "delims=" %%i in (
'dir /b /s "%rootdir%\%file%" > output.txt') do (
if "!folder!"=="%%~dpi" (
set /a n+=1
) else (
if !n! GTR 0 echo !folder!^;!n!
set n=1
set folder=%%~dpi
)
)
)
 
Justin Fancy said:
Anyway, the script doesn't seem to work for me?

It will not work because you changed it to redirect all DIR output to
output.txt file so FOR command doesn't have anything to process. In
following example command_2 will never execute:

for /f "delims=" %%i in ('command_1 > output.txt') do (command_2)
 
Justin Fancy said:
So how would I program this correctly so I can ouput it to a textfile?

Depends on what do you mean by "it". If you want script output to be saved
to a file, don't alter script itself, just use:

script.cmd > output.txt

If you need to duplicate script output to both stdout AND to a file, use:

for /f "delims=" %%i in ('script.cmd') do (
echo %%i
echo %%i >>output.txt
)
 
Back
Top