Get full path directory list on both recursive and non-recursive dir command

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???
0
Scott
5/14/2010 1:12:48 AM
windowsxp.general 3897 articles. 1 followers. Follow

5 Replies
643 Views

Similar Articles

[PageSpeed] 3

On May 14, 11:12=A0am, Scott Bass <sas_l_...@yahoo.com.au> 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) =A0dir "C:\Path\To\My\Files\*.foo" /b /s
>
> What fails (returns filename only)
>
> 2) =A0dir "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? =A0All 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.
0
Scott
5/14/2010 1:35:30 AM

"Scott Bass" <sas_l_739@yahoo.com.au> 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 

0
Pegasus
5/14/2010 6:32:05 AM
On May 14, 4:32=A0pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "Scott Bass" <sas_l_...@yahoo.com.au> 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) =A0dir "C:\Path\To\My\Files\*.foo" /b /s
>
> > What fails (returns filename only)
>
> > 2) =A0dir "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? =A0All 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 abo=
ut
> it. It does not fully emulate the dir command but it will return a full p=
ath
> when invoked with a folder name.
>
> @echo off
> for /F "delims=3D" %%a in ('echo %1') do set Folder=3D%%~dpnxa
> for /F "delims=3D" %%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=3DY|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.
0
Scott
5/14/2010 7:54:15 AM

"Scott Bass" <sas_l_739@yahoo.com.au> wrote in message 
news:40fc94f2-d0d2-42bd-9576-f9eb42ebc55e@k29g2000yqh.googlegroups.com...
> On May 14, 4:32 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
>> "Scott Bass" <sas_l_...@yahoo.com.au> 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.
 

0
Pegasus
5/14/2010 9:25:51 AM
"Scott Bass" <sas_l_739@yahoo.com.au> 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)


0
Don
5/14/2010 12:50:09 PM
Reply:

Similar Artilces:

installing a non-MS font into word
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Hi, I'm trying to download a free font called scriptina <http://www.1001fonts.com/font_details.html?font_id=2873> into word. It won't show up? I was able to get it to install into the text editor. any suggestions?? thanks! heatherc heatherc@officeformac.com wrote: > I'm trying to download a free font called scriptina > <http://www.1001fonts.com/font_details.html?font_id=2873> > into word. > > It won't show up? I was able to get it to install into the text editor. Install fonts in your ma...

i get error 404 not found when trying to download
I'm trying to download nokia pc suite to windows xp to upload gallery onto the computer but get error message404 not found - how can i download this pc suite please -- Krysy Albutt Krysy Albutt wrote: > I'm trying to download nokia pc suite to windows xp to upload gallery > onto the computer but get error message404 not found - how can i > download this pc suite please Care to enlighten us how this pertains to: - 1) Microsoft 2) Publisher 3) Windows If you're having problems downloading from the *NOKIA* site where do you think you should be directing your ...

Non US Dollar accounts do not show in Settings for Active Sync
I am currently using Microsoft Money 2006 for both my desktop and my pocket pc device. I am attempting to sync some of my accounts to my pocket pc device. However, it seems that the options for Active Sync is only shows acocunts that are using US Dollar as the currency. I would like to sync accounts that are using Singapore dollars. Any way I can do this? No. You can only synchronize accounts which are in your base currency, which appears to be US Dollars in your case. -- Glyn Simpson, Microsoft MVP - Money http://money.mvps.org Check http://money.mvps.org/faq/default.aspx for ...

How to get Calendar to send me reminders
I have changed my e-mail address but for some reason I cannot get Calendar to send reminders to my new address - I think I have carried out all that is necessary to effect the changover but I am not getting reminders sent. Can anyone help please? Is the Calendar Live ID based and accessible at Calendar.live.com ? -- ....winston ms-mvp mail "Dabardevon" wrote in message = news:FDC2B3B2-EDE4-41B1-BFC4-C0F9ED59CFB9@microsoft.com... I have changed my e-mail address but for some reason I cannot get = Calendar to send reminders to my new address - I think I have...

Some recipients get the attachment, some get winmail.dat
This one has me baffled. We are using Exchange 2000 and Outlook 2000 and have been for 8 months. No previous problems with attachments (.doc, .xls, .jpg). About 2 weeks ago, we started hearing from certain recipients that the attachment wasn't arriving; instead they were getting an unreadable file called winmail.dat. MS says that this is because the sender is using Rich Text to format the email. We have changed the senders to use Plain Text and still have the same problem. If the email is sent to several recipients, some will get the attachment fine, some will not. This didn'...

How to get the CScrollBar's Handle in CTreeCtrl?
Hey,All: I thought I have a problem when I trid to get the CScrollBar's handle from my CTreeCtrl extended handle. Can anybody tell me whether I can get the handle of the CScrollBar from the CTreeCtrl? Thanks in advance! Carl :-| Carl wrote: > Hey,All: > > I thought I have a problem when I trid to get the CScrollBar's handle from > my CTreeCtrl extended handle. > Can anybody tell me whether I can get the handle of the CScrollBar from the > CTreeCtrl? > > Thanks in advance! > Carl > :-| > > Sorry, it is not that simple. The scroll bars that...

numbering multilevel list word 2007
trying to use a multilevel number list and when I hit ENTER (return) the numbering stops (the icon for numbering become un-highlighted) If this is numbering attached to headings, note that, by default, the Normal style will be applied to text when you press Enter (at the end of a heading). You can change the "Style for following paragraph" in the style definition for the relevant heading(s). -- Stefan Blom Microsoft Word MVP "dheuermann" <dheuermann@discussions.microsoft.com> wrote in message news:EEF7E0F7-76A1-4B55-98B3-981E303C7A68@microsoft.co...

A Crystal Beginner
I am using Crystal 9.2.4.77 and have loaded the Crystal enhancements. Now I want to do against the CRM database. What do I do? I thought I would create a data source to the CRM SQLserver, which I did, then connect to it through Crystal Reports. That works, but when I drill down on the AAA_MSCRM database to choose my tables, it shows me dbo as the only option (where did this come from??) and under that are just a few generic tables. No CRM tables. Something's not quite right. What am I missing? file - log on to aps server "KBLawson" <klawson@aetinc.com> wrote in ...

Cannot get fast forward or fast reverse to work with WMP 11
I am running Vista Home Premium on a HP G 217-EM Notebook which comes pre-installed with Windows Media Player 11. When I play cds and try to fast forward or fast reverse by keeping the fast forward or fast reverse buttons constantly depressed nothing happens. Why is this, and can anyone come up with a solution? Many thanks This doesn't work on my system either, so it's probably just a limitation of WMP. Fast forward and fast reverse should work fine when you rip the CD's to MP3 or WMA files, and play these files instead. Regards -- Tim De Baets http://www....

Windows 2008 and long paths
Hi! The Vista shell has some support for paths longer than MAX_PATH (260 chars): http://blogs.msdn.com/michkap/archive/2006/12/13/1275292.aspx Does the 2008 shell have the same (or better) support? Kind regards, Thomas ...

My windows giveth xml and it taketh away! Include path!
I wrote a screensaver, via Visual Studio 2003 in C# and I decided a wiser choice for me was to use an xml file to save my configs. Btw: I wonder if this is why every bit of documentation I've found for saving configuration info in an xml file speak of only doing this for web programming in fact, I get the impression that they have been slipped a mickey that made them forget that there are programs out there that are not web based, but I digress ... I could have done a regular config files be just a regular text file, but I figured, I might as well do it with xml like everyone else ...

Get paid while you get online!!
I found a great Internet company - Cashfiesta.com - that has created a product everyone can benefit from. They pay you while you work or play on your computer. All you need to do is keep their software - the FiestaBar=99 - active while you are online. They even pay you when your friends are using their computers. Unlike other companies, Cashfiesta gives you control over how much money you earn. They have an individual payrate based on the number of Special Offers you sign up for. As some of these offers are free, you can increase your payrate up to 33 times without spending a penny. It's...

Add new record using first available non-numeric ID; update two ta
Access 2003, Windows XP Pro SP2 I have two tables, tblDed and tblVendor. tblDed contains two columns (DedID and Avail). The first column contains a list of all DedIDs allowed to be used. The second is a Yes/No choice indicating whether or not that DedID has been used already. tblVendor contains multiple columns with misc. data relevant to the Vendor. I want to create a form that will accomplish three things: 1. Use the next available unused DedID when a command button on a referring menu page (frmMenu, btnNew) is pressed. 2. Mark the now-used DedID in tblDed as "No" - no ...

Distribution List permissions #2
Exchange 2003 in native mode. How do I protect a DL so that only certain IT personnel can add/remove members to this DL? There seems to be someone that has permissions to modify some of the DLs in our environment and I need to prevent that from happening. Thanks. Distribution Groups are AD objects and have permissions/ACLs just like any other AD object. Modify the permissions to restrict who has rights to change it. -- Bharat Suneja MVP - Exchange www.zenprise.com NEW blog location: www.exchangepedia.com/blog ---------------------------------------------- "Edward" <Edwa...

Customizing marketing list view in 3.0
I have created a marketing list in CRM 3.0 (member type: contact) but the marketing list member view only gives me the name, business phone, and city. I need to add fields including the company name or this list is completely useless. The customization options I found only allows changes to the view that contains the list of marketing lists, not the member list. How do I add fields to this view? I have a similar problem and tried to change views on contacts and accounts - associated view and it did not change the mkt members view - looking for help as well. "jjohnson" w...

Can't get auto-update (update) to install
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC I've been trying to manually check for updates to Word 2008, and I get a &quot;critical update&quot; notice, asking me to install auto-update. When I try to install it, I cannot. It just keeps repeating the attempt, in an &quot;endless loop.&quot; What to do? <br> Thank you. ...

Spreadsheet getting corrupted
Hello All: I have a relatively large spreadsheet. I am getting errors (see after my signature line). What could be causing these errors? Is it that the spreadsheet is too large? Thanks Deguza -------------------------------------------------------- Microsoft Office Excel File Repair Log Errors were detected in file 'C:\Documents and Settings\deguza\My Documents\sales\Sales_2006_2007.xls' The following is a list of repairs: Global PivotTable report information was repaired due to integrity problems. Global PivotTable report information was repaired due to integrity problems. Glo...

Reg getting the next IV Document Number field !
Hi, I am creating a window in dexterity similar to the item transaction entry window (Transactions>Inventory> Transaction Entry). In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field. I wanted to know if there is any function , or table that i can access to get the next document number in the new window that i am creating. Thanks, swetha -- swetha >In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field.< T...

How do I get??
Sorry if this seems a fairly easy question to you guys. I have a spreadsheet and I need to get the current system time into a cell. The format of the time is hh:mm am/pm. Any assistance would be most helpful. Hi try =INT(NOW()) in this cell and format is to your needs -- Regards Frank Kabel Frankfurt, Germany PM wrote: > Sorry if this seems a fairly easy question to you guys. > > I have a spreadsheet and I need to get the current system time into a > cell. The format of the time is hh:mm am/pm. > > Any assistance would be most helpful. PM, in the cell you want pu...

Pulldown List to open Workbook.
I have a supplier who updates his pricelist via several spreadsheets. I want to create an interface so that I may access the appropriate pricelist (workbook) by simply selecting the proper category from a pulldown menu (list). So basically, if I select "Piping" from the pulldown menu, it would open "Piping.xls" either within my main workbook or by itself. I have no macro experience so I was hoping I could do this without using them... is this possible? Opening a workbook from a dropdown box requires a macro. You could, however, create a list of links to your workbooks (...

Get notified when Out of Office is on
I am using Outlook 2007. With 2003, when returning from leave, I used to get a notification that the Outlook out of office was still on and asking me if I wanted to switch it off. This reminder no longer appears with 2007. How can I switch this setting on so that I get the notification? "Mary Ann" <MaryAnn@discussions.microsoft.com> wrote in message news:ED5533A7-D0EA-41B8-B1A0-A9D15FB6FD98@microsoft.com... >I am using Outlook 2007. With 2003, when returning from leave, I used to get > a notification that the Outlook out of office was still on and asking me ...

Getting Control ID in Active X control
GetWindowLong return 0. You need to call GetDlgCtrlID from outside the activex control as the function available within the control returns an arbitrary value of zero. Take a look at this article http://xendra.ens.uabc.mx/~sinfante/loo/libro/ch17_4.htm particularly the paragraph preceeding the title "MFC and Ambient Properties". This really begs the question why you want the ID in the first place as activex controls have to be fully self containing to operate - with a few exceptions where sibling controls need to be able to locate each other. - Tim "ytv" <...

over VPN, it gets stuck when sending outgoing email
When I use VPN to connect to work from home, the outlook can not finish sending outgoing emails. The progress bar moves to the end but then stops there forever. It can never finish. The receiving of new incoming emails work fine. All other network functionality works, e.g. internet browsing, telnet, ftp, etc, all work fine. My system is win2k. I use linksys wireless DSL router. I'd appreciate any hint! Are you using Exchange server? I'd set up your mail profile to prompt you to work offline or online - when using VPN, work offline with scheduled syncs. If not using exchange, pos...

Get photos from a camera
I have an asp.net intranet application that I need to upload 1 or all photos from a digital camera at a PC workstation. We are using DataGrids and GridViews to display them on the web once they are uploaded but need something at the client. I assume I need some sort of ActiveX process or something. Has anyone run into a solution for this need? Thanks. -- David "DavidC" <dlchase@lifetimeinc.com> wrote in message news:2B061F4F-B548-4AA4-96FA-2F87383192D2@microsoft.com... > I have an asp.net intranet application that I need to upload 1 or all > photos ...

how to get the format of this cell right?
When I let go: Selection.Replace " ", Replacement:="-", Lookat:=xlPart, _ SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False " " is entered by means of an array: Words = Array(" ", "+", "/", "---", "--", "&") on a cell containing: 5 a I would expect to get: 5-a as a result. Unfortunately, it produces 5:00:00-AM. How can I solve this tiny but frustrating problem? best regards Pet...