Get full path directory list on both recursive and non-recursive dircommand

  • Thread starter Thread starter Scott Bass
  • Start date Start date
S

Scott Bass

Guest
This post could easily be titled "Why Unix is so much better than

Windows", but that would likely ruffle a few feathers...



I have the following seemingly simple requirements:



1) Directory list of *.foo files, recursive to a particular root

directory

2) Directory list of *.foo files, in the root directory only



The list has to be returned as a full path to the files.



What works (returns full path)



1) dir "C:\Path\To\My\Files\*.foo" /b /s



What fails (returns filename only)



2) dir "C:\Path\To\My\Files\*.foo" /b



I've also investigated the FOR command, it has similar (but different)

shortcomings.



Short of copying a port of the Unix ls command to every user's machine

(not an option), or piping the output from dir into findstr to

overcome its shortcomings, is there any way to coax the dir command to

always return the full path to the file, whether recursive or not?



The dir command has been around since the dawn of time, why does it

still suck? All the brilliant minds in Redmond, and they can't match

the Unix ls and find commands???
 
Get full path directory list on both recursive and non-recursivedir command

On May 14, 11:12 am, Scott Bass wrote:

> This post could easily be titled "Why Unix is so much better than

> Windows", but that would likely ruffle a few feathers...

>

> I have the following seemingly simple requirements:

>

> 1) Directory list of *.foo files, recursive to a particular root

> directory

> 2) Directory list of *.foo files, in the root directory only

>

> The list has to be returned as a full path to the files.

>

> What works (returns full path)

>

> 1)  dir "C:\Path\To\My\Files\*.foo" /b /s

>

> What fails (returns filename only)

>

> 2)  dir "C:\Path\To\My\Files\*.foo" /b

>

> I've also investigated the FOR command, it has similar (but different)

> shortcomings.

>

> Short of copying a port of the Unix ls command to every user's machine

> (not an option), or piping the output from dir into findstr to

> overcome its shortcomings, is there any way to coax the dir command to

> always return the full path to the file, whether recursive or not?

>

> The dir command has been around since the dawn of time, why does it

> still suck?  All the brilliant minds in Redmond, and they can't match

> the Unix ls and find commands???




P.S.: Create two files, C:\Temp\foo.foo and C:\Temp\foo.fooxxx. Then

issue the command dir C:\Temp\*.foo. It returns both files. If I'd

wanted *.fooxxx I'd have asked for it. Instead I have to workaround

this bug in my code that is processing the directory list.
 
Get full path directory list on both recursive and non-recursive dir command

"Scott Bass" wrote in message

news:d2702924-caf0-4e24-ba2b-bff4b0682ed0@i10g2000yqh.googlegroups.com...

> This post could easily be titled "Why Unix is so much better than

> Windows", but that would likely ruffle a few feathers...

>

> I have the following seemingly simple requirements:

>

> 1) Directory list of *.foo files, recursive to a particular root

> directory

> 2) Directory list of *.foo files, in the root directory only

>

> The list has to be returned as a full path to the files.

>

> What works (returns full path)

>

> 1) dir "C:\Path\To\My\Files\*.foo" /b /s

>

> What fails (returns filename only)

>

> 2) dir "C:\Path\To\My\Files\*.foo" /b

>

> I've also investigated the FOR command, it has similar (but different)

> shortcomings.

>

> Short of copying a port of the Unix ls command to every user's machine

> (not an option), or piping the output from dir into findstr to

> overcome its shortcomings, is there any way to coax the dir command to

> always return the full path to the file, whether recursive or not?

>

> The dir command has been around since the dawn of time, why does it

> still suck? All the brilliant minds in Redmond, and they can't match

> the Unix ls and find commands???




It never ceases to amuse me when people extol the virtues of a Unix or an

Apple Mac machine with Windows itself. It's like telling your wife "my

mother cooks much better than you do". Well, go and live with your mother!

Each OS has its peculiarities - that's just the way it is. You can work

around your particular problem with this batch file if you care a lot about

it. It does not fully emulate the dir command but it will return a full path

when invoked with a folder name.



@echo off

for /F "delims=" %%a in ('echo %1') do set Folder=%%~dpnxa

for /F "delims=" %%a in ('dir /b %1') do echo %Folder%\%%a
 
Get full path directory list on both recursive and non-recursivedir command

On May 14, 4:32 pm, "Pegasus [MVP]" wrote:

> "Scott Bass" wrote in message

>

> news:d2702924-caf0-4e24-ba2b-bff4b0682ed0@i10g2000yqh.googlegroups.com...

>

>

>

> > This post could easily be titled "Why Unix is so much better than

> > Windows", but that would likely ruffle a few feathers...


>

> > I have the following seemingly simple requirements:


>

> > 1) Directory list of *.foo files, recursive to a particular root

> > directory

> > 2) Directory list of *.foo files, in the root directory only


>

> > The list has to be returned as a full path to the files.


>

> > What works (returns full path)


>

> > 1)  dir "C:\Path\To\My\Files\*.foo" /b /s


>

> > What fails (returns filename only)


>

> > 2)  dir "C:\Path\To\My\Files\*.foo" /b


>

> > I've also investigated the FOR command, it has similar (but different)

> > shortcomings.


>

> > Short of copying a port of the Unix ls command to every user's machine

> > (not an option), or piping the output from dir into findstr to

> > overcome its shortcomings, is there any way to coax the dir command to

> > always return the full path to the file, whether recursive or not?


>

> > The dir command has been around since the dawn of time, why does it

> > still suck?  All the brilliant minds in Redmond, and they can't match

> > the Unix ls and find commands???


>

> It never ceases to amuse me when people extol the virtues of a Unix or an

> Apple Mac machine with Windows itself. It's like telling your wife "my

> mother cooks much better than you do". Well, go and live with your mother!

> Each OS has its peculiarities - that's just the way it is. You can work

> around your particular problem with this batch file if you care a lot about

> it. It does not fully emulate the dir command but it will return a full path

> when invoked with a folder name.

>

> @echo off

> for /F "delims=" %%a in ('echo %1') do set Folder=%%~dpnxa

> for /F "delims=" %%a in ('dir /b %1') do echo %Folder%\%%a




Hi Pegasus,



Thanks for the help. I do appreciate it (as well as your previous

help). And I'm glad I amused you. You still haven't addressed

whether the Windows dir command sucks or not ;-)



However, your analogy falls down, since this is an arranged marriage.

I'd love to go live with my mother, but someone put a gun to my head

and said I had to marry this man.



Re: your batch file, I want to give the user the ability to specify a

parm, recursive=Y|N and, no matter what they put for the root

directory, a full path for the matching files is returned. I need to

do it in a single command string, not a batch file, since I can't copy

a batch file to hundreds of user's machines.



I may just have to tell them "if you don't want recursion, specify a

root directory deep enough that does not contain sub-directories", and

just hard code the /s. And if sub-directories are later created after

the fact, the process may break.



All because the dir command, that's been around for 30+ years, sucks.
 
Get full path directory list on both recursive and non-recursive dir command

"Scott Bass" wrote in message

news:40fc94f2-d0d2-42bd-9576-f9eb42ebc55e@k29g2000yqh.googlegroups.com...

> On May 14, 4:32 pm, "Pegasus [MVP]" wrote:

>> "Scott Bass" wrote in message

>>

>> news:d2702924-caf0-4e24-ba2b-bff4b0682ed0@i10g2000yqh.googlegroups.com...

>>

>>

>>

>> > This post could easily be titled "Why Unix is so much better than

>> > Windows", but that would likely ruffle a few feathers...


>>

>> > I have the following seemingly simple requirements:


>>

>> > 1) Directory list of *.foo files, recursive to a particular root

>> > directory

>> > 2) Directory list of *.foo files, in the root directory only


>>

>> > The list has to be returned as a full path to the files.


>>

>> > What works (returns full path)


>>

>> > 1) dir "C:\Path\To\My\Files\*.foo" /b /s


>>

>> > What fails (returns filename only)


>>

>> > 2) dir "C:\Path\To\My\Files\*.foo" /b


>>

>> > I've also investigated the FOR command, it has similar (but different)

>> > shortcomings.


>>

>> > Short of copying a port of the Unix ls command to every user's machine

>> > (not an option), or piping the output from dir into findstr to

>> > overcome its shortcomings, is there any way to coax the dir command to

>> > always return the full path to the file, whether recursive or not?


>>

>> > The dir command has been around since the dawn of time, why does it

>> > still suck? All the brilliant minds in Redmond, and they can't match

>> > the Unix ls and find commands???


>>

>> It never ceases to amuse me when people extol the virtues of a Unix or an

>> Apple Mac machine with Windows itself. It's like telling your wife "my

>> mother cooks much better than you do". Well, go and live with your

>> mother!

>> Each OS has its peculiarities - that's just the way it is. You can work

>> around your particular problem with this batch file if you care a lot

>> about

>> it. It does not fully emulate the dir command but it will return a full

>> path

>> when invoked with a folder name.

>>

>> @echo off

>> for /F "delims=" %%a in ('echo %1') do set Folder=%%~dpnxa

>> for /F "delims=" %%a in ('dir /b %1') do echo %Folder%\%%a


>

> Hi Pegasus,

>

> Thanks for the help. I do appreciate it (as well as your previous

> help). And I'm glad I amused you. You still haven't addressed

> whether the Windows dir command sucks or not ;-)




*** I agree, there is a glaring inconsistency.



> However, your analogy falls down, since this is an arranged marriage.

> I'd love to go live with my mother, but someone put a gun to my head

> and said I had to marry this man.




*** If your dislike of Windows is sufficiently strong then you

*** need to move into a Unix/Linux environment.



> Re: your batch file, I want to give the user the ability to specify a

> parm, recursive=Y|N and, no matter what they put for the root

> directory, a full path for the matching files is returned. I need to

> do it in a single command string, not a batch file, since I can't copy

> a batch file to hundreds of user's machines.




*** It may be possible to it with a single command string but I am

*** not sufficiently motivated to spend an hour on the issue. If you

*** repost your question in alt.msdos.batch.nt then you will get a

*** dozen excellent answers in no time at all - the experts in that

*** group love this type of challenge.



> I may just have to tell them "if you don't want recursion, specify a

> root directory deep enough that does not contain sub-directories", and

> just hard code the /s. And if sub-directories are later created after

> the fact, the process may break.

>

> All because the dir command, that's been around for 30+ years, sucks.
 
Get full path directory list on both recursive and non-recursive dir command

"Scott Bass" wrote in message

news:d2702924-caf0-4e24-ba2b-bff4b0682ed0@i10g2000yqh.googlegroups.com...



> This post could easily be titled "Why Unix is so much better than

> Windows", but that would likely ruffle a few feathers... . . .

> The dir command has been around since the dawn of time, why does it

> still suck? All the brilliant minds in Redmond, and they can't match

> the Unix ls and find commands???




Factual answers include:

1. MS-DOS is proprietary software i.e. commercial market prospects

govern whether it is improved or not.

2. But Linux is open-source, i.e. open to improvement by anyone

capable of making an improvement.

But SB knew this already: so that it is not clear why he posted.



--

Don Phillipson

Carlsbad Springs

(Ottawa, Canada)
 
Back
Top