For Command - can I do IN clause: ('cmd 1 & cmd 2') ???

G

Guest

Hi I want to do more than 1 command in the IN clause of a FOR statement as
above (generically) or as in the below (specifically):

for /F %Q in ('( dir . /A:D /B /S /O:N & cd )')
do (for /F %R in ('dir %Q\*.* /A:-D /B')
do echo %~fxR )

I am trying to get a listing of all files in the directory structure at and
below the <current directory> - BUT I need to see the files in the <current
directory> LAST i.e. after all of the sub directories and their descendants.
I need this because when filenames appear more than once, the <current
directory takes precedence) otherwise they are to be considered in alpha
order.
 
P

Pegasus \(MVP\)

dino said:
Hi I want to do more than 1 command in the IN clause of a FOR statement as
above (generically) or as in the below (specifically):

for /F %Q in ('( dir . /A:D /B /S /O:N & cd )')
do (for /F %R in ('dir %Q\*.* /A:-D /B')
do echo %~fxR )

I am trying to get a listing of all files in the directory structure at and
below the <current directory> - BUT I need to see the files in the <current
directory> LAST i.e. after all of the sub directories and their descendants.
I need this because when filenames appear more than once, the <current
directory takes precedence) otherwise they are to be considered in alpha
order.

No need for a "for" loop. Try this instead:

dir /A:D /B /S /O:N
 
G

Guest

I am sorry maybe I was unclear:

I need to see all the files in the subdirectories BEFORE I see the files in
the <CURRENT DIRECTORY>

SO if I am at the root and i have files/directories as follows

\dog.txt
\cat.txt
\mouse.txt
\bird.txt
\fourLeggedAnimals\dog.txt
\fourLeggedAnimals\cat.txt
\fourLeggedAnimals\mouse.txt
\pets\dog.txt
\pets\cat.txt
\pets\mouse.txt
\pets\bird.txt
\twoLeggedAnimals\bird.txt


I need to process the files in this order:

\fourLeggedAnimals\dog.txt
\fourLeggedAnimals\cat.txt
\fourLeggedAnimals\mouse.txt
\pets\dog.txt
\pets\cat.txt
\pets\mouse.txt
\pets\bird.txt
\twoLeggedAnimals\bird.txt
\dog.txt
\cat.txt
\mouse.txt
\bird.txt


That is why I want to do

dir . /A:D /B /S /O:N to first get me the list of subdirectories
then cd to get me the name of the <current directory>
yielding:

\fourLeggedAnimals\
\pets\
\twoLeggedAnimals\
\


Then I can do a dir on each of these directories

dir \fourLeggedAnimals\
dir \pets\
dir \twoLeggedAnimals\
dir \

yielding me the highest level directory last
 
P

Pegasus \(MVP\)

dino said:
I am sorry maybe I was unclear:

I need to see all the files in the subdirectories BEFORE I see the files in
the <CURRENT DIRECTORY>

SO if I am at the root and i have files/directories as follows

\dog.txt
\cat.txt
\mouse.txt
\bird.txt
\fourLeggedAnimals\dog.txt
\fourLeggedAnimals\cat.txt
\fourLeggedAnimals\mouse.txt
\pets\dog.txt
\pets\cat.txt
\pets\mouse.txt
\pets\bird.txt
\twoLeggedAnimals\bird.txt


I need to process the files in this order:

\fourLeggedAnimals\dog.txt
\fourLeggedAnimals\cat.txt
\fourLeggedAnimals\mouse.txt
\pets\dog.txt
\pets\cat.txt
\pets\mouse.txt
\pets\bird.txt
\twoLeggedAnimals\bird.txt
\dog.txt
\cat.txt
\mouse.txt
\bird.txt


That is why I want to do

dir . /A:D /B /S /O:N to first get me the list of subdirectories
then cd to get me the name of the <current directory>
yielding:

\fourLeggedAnimals\
\pets\
\twoLeggedAnimals\
\


Then I can do a dir on each of these directories

dir \fourLeggedAnimals\
dir \pets\
dir \twoLeggedAnimals\
dir \

yielding me the highest level directory last

This is just as simple:

@echo off
dir /AD
for /d %%a in (*.*) do dir "%%a" /B /S /O:N
dir /A:-D /B /S /O:N
 
G

Guest

Thanks for your help Pegasus but while your answer works, (although I do not
think you need the first dir /AD and you meant /A:D not /A:-D on the last
dir) it still is two commands as I had at first and does not let me pass two
commands to an outer wrapping for command.

I need to parse the files in the generated list.
SO is there a syntax whereby I can do: ('dir . /A:D /B /S /O:N & cd ')
or your simpler
('for /d %%a in (*.*) do dir "%%a" /B /S /O:N & dir /A:-D /B /S /O:N ')

As a commnd IN lcause to an outer for statement?



for /F %Q in ('( dir . /A:D /B /S /O:N & cd )')
do (for /F %R in ('dir %Q\*.* /A:-D /B')
do echo %~fxR )
 
P

Pegasus \(MVP\)

I'm sure there is a way to do what you want to do.
So far you have presented your partial solutions,
which you say do not work properly. Instead you
should start with a description of your ***functional
requirements***:

In other words: What exactly do you expect your
command to do?
 
G

Guest

Thanks again for your perseverance.

I need to parse each line of a list of files. The list must be presented in
the order I originally described as they partially, functionaly "overlap" one
another and my precedane requirements will be then met.

As I said the list must be in this order:

I am trying to get a listing of all files in the directory structure at and
below the <current directory> - BUT I need to see the files in the <current
directory> LAST i.e. after all of the sub directories and their descendants.
I need this because when filenames appear more than once, the <current
directory takes precedence) otherwise they are to be considered in alpha
order.
 
P

Pegasus \(MVP\)

The three-line batch file below will list all files in each
of the subdirectories that hang off the current directory.
It will then list every file stored in the current directory.

@echo off
for /d %%d in (*.*) do for /F "tokens=*" %%* in ('dir "%%d" /B /a-d /S
/O:N') do echo %%*
for /F "tokens=*" %%* in ('dir /B /a-d /O:N') do echo %cd%\%%*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top