extracting info from string

  • Thread starter Thread starter Johnnie Walker
  • Start date Start date
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.
 
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
 
Back
Top