You are not logged in.

#1 22 Mar 2007 22:44

NDog
Member
From: New Zealand
Registered: 31 May 2006
Posts: 121
Website

FOR with LFN?

SET _lfn=c:\my documents\lfn.txt
FOR /F "tokens=1* delims==" %%G IN (%_lfn%) DO SET %%G=%%H

A problem I had for a long time now, but is it possible to use for commands with a long file name, or do you need it to be in the same directory to process for commands? I tried double quotes and single quotes but they didnt work, maybe the context is wrong

Last edited by NDog (23 Mar 2007 04:15)


cmd, vbs, ps, bash
autoit, python, swift

Offline

#2 23 Mar 2007 00:12

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: FOR with LFN?

you missed an underscore

SET _lfn

or else just use %lfn%

Offline

#3 23 Mar 2007 09:46

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: FOR with LFN?

For once, Windows Help has all the answers.  Important bits are in bold...

Windows 'FOR' Help wrote:

<snip>

    or, if usebackq option present:

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

<snip>

usebackq     - specifies that the new semantics are in force,
                  where a back quoted string is executed as a
                  command and a single quoted string is a
                  literal string command and allows the use of
                  double quotes to quote file names in
                  file-set*.

<snip>

*I've corrected the slightly misleading original word that is here.

Thus your corrected FOR statement would need to look something like this:

FOR /F "usebackq tokens=1* delims==" %%G IN ("%_lfn%") DO SET %%G=%%H

Last edited by bluesxman (23 Mar 2007 09:49)


cmd | *sh | ruby | chef

Offline

#4 23 Mar 2007 13:20

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: FOR with LFN?

Good point, I've just edited the FOR /F page to add that usebackq option.

thanks bluesxman

Offline

Board footer

Powered by