extracting info from text.txt to variable

August 1, 2012 at 07:30:00
Specs: windows 98 dos
Hi I am using windows 98 dos


I have a text.txt with these info ...

d:\folder\file1.txt
d:\folder\file2.txt
d:\folder\file3.txt
d:\folder\file4.txt
d:\folder\file5.txt


how can i extract the info to the following variable

%drive% = d
%latestfile%=folder\file5.txt


See More: extracting info from text.txt to variable

Report •

#1
August 1, 2012 at 22:58:58
i don't think straight batch (pre-XP) will swing it. You need another language, or an app. I prefer languages, but that's just me. vbscript is excellent. QBasic, or even gwbasic can do what you want. they can be downloaded. vbscript support is probably on-board your system. (search for *.vbs, cscript.exe, wscript.exe, to find out.)
set fso=createobject("scripting.filesystemobject")
set ffile=fso.opentextfile("filelist.txt",1)
do while not ffile.atendofstream
last=x
x=ffile.readline
loop
'sometimes, there is discrepancy, which line is last: null can cause problems.
wscript.stdout.echo "last file is: "&last
wscript.stdout.echo "last LINE is: "&x
zz=split(last,":",-1)(0)
wscript.stdout.echo "drive is: "&zz
'-----------end vbscript
THEN, you need to place the data where you want it. this just echos...
to run:
(save as, f/e test.vbs)
(create a dummy file with names as needed, format as described)
cscript /nologo test.vbs
'end

Report •

#2
August 8, 2012 at 12:05:51
@echo off
for /f "tokens=1,2,3,4 delims=^\" %%D IN (c:\data1.txt) DO (set drive1=%%D && set latestfile=%%E^\%%F)

ECHO DRIVE : %drive1%
ECHO LATESTFILE : %latestfile%

pause

:: mike


Report •
Related Solutions


Ask Question