DIR /s Command on Mapped Drives

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
dcampbe1
Posts: 11
Joined: 06 Jul 2009 09:20

Re: DIR /s Command on Mapped Drives

#16 Post by dcampbe1 » 26 Sep 2016 09:21

Squashman wrote:
dcampbe1 wrote:
Squashman wrote:Give this a try from the cmd prompt.

Code: Select all

for /D /R %G in (*) do echo %G

That's exactly what the doctor ordered -- almost. It does what I want it to but lists literally ever folder on the entire drive. I would like to use the same command with a filter to give me only folders with names containing "BI.$BIRIS".

I know this isn't a fix for whatever problem I have with Win10 but it does the job. I only wish I knew the "for" command as well as the old DOS.

The asterisk is a wild card. It is no different then when you were using *.* with your DIR command.


Running with the * command I get a list of 1143 folder names. I am looking for only these threefolder names: Y:\BlueIris\2014-04.BI.$BIRIS, Y:\BlueIris\2014-05.BI.$BIRIS, Y:\BlueIris\2016-02.BI.$BIRIS. Without success I've played around with numerous variations of the folder set, the latest being, "for /D /R %G in ('dir /s /a:d "y:\BIRIS*"') do echo %G >> testresults.txt". Isn't there a cleaner way of getting only the three desired folder names?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: DIR /s Command on Mapped Drives

#17 Post by Squashman » 26 Sep 2016 09:47

dcampbe1 wrote:Running with the * command I get a list of 1143 folder names. I am looking for only these threefolder names: Y:\BlueIris\2014-04.BI.$BIRIS, Y:\BlueIris\2014-05.BI.$BIRIS, Y:\BlueIris\2016-02.BI.$BIRIS. Without success I've played around with numerous variations of the folder set, the latest being, "for /D /R %G in ('dir /s /a:d "y:\BIRIS*"') do echo %G >> testresults.txt". Isn't there a cleaner way of getting only the three desired folder names?

I was not inferring that you use the DIR command inside the FOR /D /R command. For one, you can't do that. You can only use commands inside the IN clause when using a FOR /F command.

I was just trying to explain that you can use wildcards within the FOR /D /R command the same way you use them with the DIR command. You way over thought the solution.

Code: Select all

for /D /R %G in (*.BI.$BIRIS) do echo %G

dcampbe1
Posts: 11
Joined: 06 Jul 2009 09:20

Re: DIR /s Command on Mapped Drives

#18 Post by dcampbe1 » 26 Sep 2016 10:17

Squashman wrote:
dcampbe1 wrote:Running with the * command I get a list of 1143 folder names. I am looking for only these threefolder names: Y:\BlueIris\2014-04.BI.$BIRIS, Y:\BlueIris\2014-05.BI.$BIRIS, Y:\BlueIris\2016-02.BI.$BIRIS. Without success I've played around with numerous variations of the folder set, the latest being, "for /D /R %G in ('dir /s /a:d "y:\BIRIS*"') do echo %G >> testresults.txt". Isn't there a cleaner way of getting only the three desired folder names?

I was not inferring that you use the DIR command inside the FOR /D /R command. For one, you can't do that. You can only use commands inside the IN clause when using a FOR /F command.

I was just trying to explain that you can use wildcards within the FOR /D /R command the same way you use them with the DIR command. You way over thought the solution.

Code: Select all

for /D /R %G in (*.BI.$BIRIS) do echo %G

OH how simple when you know how. Now it's absolutely perfectly what I needed. Thank you for your unrealistic persistence and perseverance. I really appreciate you sharing your knowledge.

Post Reply