extracting info from string

J

Johnnie Walker

problem: I have the line in a log
"-r-xr-xr-x 1 owner group 25423 Nov 16 1993 long file
name.TXT"


I need to set a variable with the file name ie:("long file name.TXT")


The problem is that as I am getting this line from an FTP log I don't
know what the file name is or whether it will have spaces on it. also
the owner/group size etc might change making the length of the string
unpredictable


any ideas/clues how I could get it using vbscript/findstr/etc ???

Any information would be greatly appreciated

Thanks in advance

JW.
 
J

Jerold Schulman

problem: I have the line in a log
"-r-xr-xr-x 1 owner group 25423 Nov 16 1993 long file
name.TXT"


I need to set a variable with the file name ie:("long file name.TXT")


The problem is that as I am getting this line from an FTP log I don't
know what the file name is or whether it will have spaces on it. also
the owner/group size etc might change making the length of the string
unpredictable


any ideas/clues how I could get it using vbscript/findstr/etc ???

Any information would be greatly appreciated

Thanks in advance

JW.

If you knew that owner and group never had spaces,
and I am assuming no quote marks:

enabledelayedexpansion
for /f "Tokens=1-8*" %%a in ('type logfilename') do (
set filename="%%i"
)

if not, then the following:
enabledelayedexpansion
for /f "Tokens=*" %%a in ('type logfilename') do (
set line=%%a
set line=!line:* Jan =!
set line=!line:* Feb =!
set line=!line:* Mar =!
set line=!line:* Apr =!
set line=!line:* May =!
set line=!line:* Jun =!
set line=!line:* Jul =!
set line=!line:* Aug =!
set line=!line:* Sep =!
set line=!line:* Oct =!
set line=!line:* Nov =!
set line=!line:* Dec =!
for /f "Tokens=2*" %%x in ('@echo !line!') do (
set filename="%%y"
)
@echo !filename!
)
endlocal

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top