Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Directory listing...

4 views
Skip to first unread message

Blue Streak

unread,
Jun 24, 2008, 11:50:59 AM6/24/08
to
If anyone could shed some light on this problem it would be much
appreciated.

I'm trying to produce a list of folders (path only, i.e. C:\Program
Files\whatever) from the following command:

dir master.dbf /s

So far, I have made the following batch file

---test.bat---
DIR "SYS_MHS.mdf" /S | FIND "Directory of" > "%temp%\tmp.txt"

FOR /F "tokens=*" %%L IN (%temp%\tmp.txt) DO (
SET var=%%%L: Directory of =%
ECHO %var%
)

I am trying to strip out the text " Directory of " from each line from
the FOR loop but I am having no luck. I just keep getting "Directory:
Directory of " with each bloody line because my substitution is not
working.

Any ideas?

TIA...

billious

unread,
Jun 24, 2008, 11:59:10 AM6/24/08
to

"Blue Streak" <rdleb...@hotmail.com> wrote in message
news:d7450eb7-a36c-4414...@j22g2000hsf.googlegroups.com...

Well, you could try

FOR /F "tokens=2*" %%L IN (%temp%\tmp.txt) DO echo %%M

but personally, I'd use

dir /s/b/a:d "SYS_MHS.mdf"

- really depends on your ultimate purpose.


H. Rodriguez

unread,
Jun 24, 2008, 12:34:36 PM6/24/08
to

"billious" <billio...@hotmail.com> wrote in message
news:486119cd$0$32031$a82e...@reader.athenanews.com...
Drop the /a:d and it works!

Thx.


Tom Lavedas

unread,
Jun 24, 2008, 12:41:39 PM6/24/08
to
On Jun 24, 11:59 am, "billious" <billious_1...@hotmail.com> wrote:
> "Blue Streak" <rdlebre...@hotmail.com> wrote in message

>
> news:d7450eb7-a36c-4414...@j22g2000hsf.googlegroups.com...
>
>
>
> > If anyone could shed some light on this problem it would be much
> > appreciated.
>
> > I'm trying to produce a list of folders (path only, i.e. C:\Program
> > Files\whatever) from the following command:
>
> > dir master.dbf /s
>
> > So far, I have made the following batch file
>
> > ---test.bat---
> > DIR "SYS_MHS.mdf" /S | FIND "Directory of" > "%temp%\tmp.txt"
>
> > FOR /F "tokens=*" %%L IN (%temp%\tmp.txt) DO (
> > SET var=%%%L: Directory of =%
> > ECHO %var%
> > )
>
> > I am trying to strip out the text " Directory of " from each line from
> > the FOR loop but I am having no luck. I just keep getting "Directory:
> > Directory of " with each bloody line because my substitution is not
> > working.
>
> > Any ideas?
>
> > TIA...
>
> Well, you could try
>
> FOR /F "tokens=2*" %%L IN (%temp%\tmp.txt) DO echo %%M
>

I don't think you actually tested this - at least not with a long
folder name with delimiters in it.

> but personally, I'd use
>
> dir /s/b/a:d "SYS_MHS.mdf"
>
> - really depends on your ultimate purpose.

Wouldn't that need to be ...

for /f "delims=" %%L in ('dir /s/b "SYS_MHS.mdf"') do echo %%~dpL

The only difference between this approach and what the OP wanted to do
is an added trailing backslash.

The OPs original problems were a failure to understand variable
substitution and a delayed expansion problem, which are solved by
(without using a temporary file) ...

FOR /F "tokens=*" %%L IN (

'DIR "SYS_MHS.mdf" /S^| FIND "Directory of"'
) DO (
SET var=%%L
call SET var=%%var:Directory of =%%
call ECHO %%var%%
)

Admittedly, it's not efficient, but it illustrates the concepts for
future reference.

BTW, there is actually a third problem: There is no leading space in
the DIR listing because of the FOR processing. Therefore, the
original substitution needed to be modified slightly to remove the
need to match a leading space. Changing the the FOR parameter to
"delims=", instead, would have preserved the leading space.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

billious

unread,
Jun 24, 2008, 3:09:26 PM6/24/08
to

"Tom Lavedas" <tglb...@cox.net> wrote in message
news:58f7d3ec-52c6-4ddf...@d1g2000hsg.googlegroups.com...

Well, true - I didn't test the

FOR /F "tokens=2*" %%L IN (%temp%\tmp.txt) DO echo %%M

as I relied on the OP's report that the file consisted of lines of the
format
"Directory of string"

Which the above line processes for me quite happily in both theory and
practice. I've tried it using lfns - well, ldns, including spaces,
"&","!","%" and "," - all seemed fine.

Or are you referring to the %temp%... filename? Agreed, in a default install
that might give a problem as the default tempdir contains a space. I just
used the OP's install which apparently didn't object.

As for the second point - yes, trying to fix a solution rather than a
problem. I assumed that the target was a directory, not a file hence the
problem appeared to be to find the directorynames in a subtree rooted at the
given "directory."

Ahem - yes, the name given makes more sense as a file, so it appears that
the problem is to find the directorynames containing the given filename.

I'd try

for /f "tokens=2*" %%L in ( ' dir /s "SYS_MHS.mdf" ^|find "\" ' ) do echo
%%M

which appears to work nicely for me with the same set of
nasty-character-containing long directorynames - and neatly avoids the
production of a tempfile and any problems arising from its name also...


Tom Lavedas

unread,
Jun 24, 2008, 3:55:46 PM6/24/08
to
On Jun 24, 3:09 pm, "billious" <billious_1...@hotmail.com> wrote:
> "Tom Lavedas" <tglba...@cox.net> wrote in message
>{snip}

>
> Well, true - I didn't test the
>
> FOR /F "tokens=2*" %%L IN (%temp%\tmp.txt) DO echo %%M
>
{snip}

Mea culpa, I had a typo in my test code. Your code works fine.

FileGod

unread,
Jul 11, 2008, 2:56:32 PM7/11/08
to
Blue Streak <rdleb...@hotmail.com> wrote:
>If anyone could shed some light on this problem it would be much
appreciated.
>I am trying to strip out the text " Directory of " from each line from
>the FOR loop but I am having no luck. I just keep getting "Directory:
>Directory of " with each bloody line because my substitution is not
>working.

>Any ideas?
Sorry I have not been in here for some time but way to get the directory
name is just CD, here is a batch file I made on Win98 machine tht might
help you I do not have it on my website yet but I will get around to it,
this is my ZipLister98.bat & garbs the file descriptions...
Please excuse any missing letters, I have to get a ney keyboard...
Oh, to get the directory name slap in CD>>Files.txt where you want it, I
hope this helps...
Lines are numbered for word wrap...
[1] @echo off
[2] goto work
[4] rem del Files.txt
[5] if "%2"=="GetDiz" goto GetDiz
[6] for %%x in (*.zip) do call %0 %%x GetDiz
[7] goto end
[9] dir/b %1>>Files.txt
[10] dir %1 | find "bytes">temp.txt
[11] type temp.txt>>Files.txt
[12] del temp.txt
[13] pkunzip -e %1 File_id.diz>nul
[14] type File_id.diz>>Files.txt
[15] if not exist File_id.diz echo File Description Not Found>>Files.txt
[16] echo -------------------------------------------->>Files.txt
[17] del File_id.diz
[18] :end

http://www.filegod.netfirms.com

0 new messages