Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Help understanding one liner

Reply
 
Old 08-27-2009   #1 (permalink)
AlexT.


 
 

Help understanding one liner

folks

I'm trying to understand the following one liner (in order to
eventually amend it)

for /f "tokens=*" %%a in ('dir /s /b *.pdf 2^>NUL') do echo %%a

I understand what it does (list all pdf files in a file structure) but
not how. Not even sure it's vbscript (sorry . Tried to google it
without much success (probably because "for" is a pretty common
term...).

Anyway some pointer / help would be much appreciated

Regards

alex

My System SpecsSystem Spec
Old 08-27-2009   #2 (permalink)
Steve


 
 

Re: Help understanding one liner

AlexT. wrote:
Quote:

>
> I'm trying to understand the following one liner (in order to
> eventually amend it)
>
> for /f "tokens=*" %%a in ('dir /s /b *.pdf 2^>NUL') do echo %%a
>
> I understand what it does (list all pdf files in a file structure) but
> not how. Not even sure it's vbscript (sorry . Tried to google it
> without much success (probably because "for" is a pretty common
> term...).
It's not VBScript; it's a batch command.

Open the Command Prompt and type "for /?" for documentation or read
<http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/for.mspx>

--
Steve

Those who know how to win are much more numerous than those who know how
to make proper use of their victories. -Polybius


My System SpecsSystem Spec
Old 08-27-2009   #3 (permalink)
Todd Vargo


 
 

Re: Help understanding one liner


"AlexT." <google@xxxxxx> wrote in message
news:97bc4c3a-357f-430c-8276-305aab78c522@xxxxxx
Quote:

> folks
>
> I'm trying to understand the following one liner (in order to
> eventually amend it)
>
> for /f "tokens=*" %%a in ('dir /s /b *.pdf 2^>NUL') do echo %%a
>
> I understand what it does (list all pdf files in a file structure) but
> not how. Not even sure it's vbscript (sorry . Tried to google it
> without much success (probably because "for" is a pretty common
> term...).
>
> Anyway some pointer / help would be much appreciated
Alex, as others mentioned, this is batch code not vbscript. To understand
how it works is going to take more than a pointer to read FOR/? help.
Actually, this is three commands on one line. FOR, DIR and ECHO but lets
look at the DIR command first.

dir /s /b *.pdf

This returns a bare directory output of all .pdf files in current and all
subdirectories. The /b tells DIR to return a bare listing (filenames only)
and the /s tells it to recurs subdirectories (this returns the full file
paths). The 2^>NUL hides any error messages. Actually, 2>NUL hides error
messages but since the command is nested within the FOR command, the output
symbol > needs to be escaped with a ^ caret. Because the FOR command used
the /f switch, this allows the FOR command to execute the DIR command
because it is enclosed within single quotes. The output of DIR is fed to the
FOR command for processing. The "tokens=*" tells the FOR command to pass
each line of output irrespective of any spaces or other delimiter
characters. The ECHO command tells it to send the output to screen.

For further information, read the help from these commands.

FOR/?
DIR/?
ECHO/?

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Old 08-28-2009   #4 (permalink)
AlexT.


 
 

Re: Help understanding one liner

On Aug 28, 6:48*am, "Todd Vargo" <tlva...@xxxxxx> wrote:
Quote:

> "AlexT." <goo...@xxxxxx> wrote in message
>
> news:97bc4c3a-357f-430c-8276-305aab78c522@xxxxxx
>
Quote:

> > folks
>
Quote:

> > I'm trying to understand the followingoneliner(in order to
> > eventually amend it)
>
Quote:

> > for /f "tokens=*" %%a in ('dir /s /b *.pdf 2^>NUL') do echo %%a
>
Quote:

> > I understand what it does (list all pdf files in a file structure) but
> > not how. Not even sure it's vbscript (sorry . Tried to google it
> > without much success (probably because "for" is a pretty common
> > term...).
>
Quote:

> > Anyway some pointer / help would be much appreciated
>
> Alex, as others mentioned, this is batch code not vbscript. To understand
> how it works is going to take more than a pointer to read FOR/? help.
> Actually, this is three commands ononeline. FOR, DIR and ECHO but lets
> look at the DIR command first.
>
> * * dir /s /b *.pdf
>
> This returns a bare directory output of all .pdf files in current and all
> subdirectories. The /b tells DIR to return a bare listing (filenames only)
> and the /s tells it to recurs subdirectories (this returns the full file
> paths). The 2^>NUL hides any error messages. Actually, 2>NUL hides error
> messages but since the command is nested within the FOR command, the output
> symbol > needs to be escaped with a ^ caret. Because the FOR command used
> the /f switch, this allows the FOR command to execute the DIR command
> because it is enclosed within single quotes. The output of DIR is fed to the
> FOR command for processing. The "tokens=*" tells the FOR command to pass
> each line of output irrespective of any spaces or other delimiter
> characters. The ECHO command tells it to send the output to screen.
>
> For further information, read the help from these commands.
>
> FOR/?
> DIR/?
> ECHO/?
>
> --
> Todd Vargo
> (Post questions to group only. Remove "z" to email personal messages)
Todd: thanks a bunch ! Most helpfull - I actually managed to
understand this one and to amend it to my liking
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
one-liner PowerShell PowerShell
Exchange Powershell one-liner to Mail-Enable Contacts PowerShell
Help Understanding INNER JOIN VB Script
Multi-line text becomes a one-liner PowerShell
Exchange 2007 "Activate the PowerShell" One liner Contest PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46