PDA

View Full Version : File Editing



rossd
12-03-2001, 10:50 AM
Hi All,

I'm not too proficient with VBScript, to be honest I am only after a couple of things out of it. I am setting up a remote backup solution for my company and am trying to edit log files automatically. Basically I need to be able to grab the last ten lines of a given file(variable in length) and export it to another file. Thats it! But I'll be damned if I can find a sample piece of code anywhere!

Any help will be gratefully received!

darkness
12-04-2001, 09:40 PM
Here is a script to do it, but you may need to modify some parts to fit your environment, I will try to note which those are if I can.

set fso = createobject("scripting.Filesystemobject")
set flatfile = FSO.opentextfile("c:\tellmes.txt")
fullfile = flatfile.readall 'Puts the whole file into the data place fullfile
alllines = split(fullfile,vblf) 'breaks the fullfile up by linefeed character puting one line per data field
count = 0
for each line in allines
tcount = tcount + 1
next
for each aline in allines
count = count + 1
if (tcount - count) <= 10 then
wscript.echo aline
end if
next

Now I don't know how you want to export it the other file and/or if that other file is in a different format. Right now this script will take the text file and run through it until the last ten lines when it will display information.

On this site there is a link to the windows 5.6 script engine. There is also a place there to download the documentation. It will help in the long run if you also look to do this.



Michael McLaughlin/images/forums/icons/smile.gif
Systems Manager
Minnesota State University Mankato