I want to run a vbscript on a local computer which goes to the H:. It has a lot of logs. Finds a log with name MTFoxadapter_*.log with the latest 2 modified files.
Later on I want to open those files and scan a few things but this is the first thing. Would be great if anyone could help me out.
Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Have you tried anything yet? There are examples of recursing through a folder if you simply search...first things first...recurse the directory you mentioned and make sure you can see all the files...next start filtering for files that meet your criteria, then work out the dates issue.
Of course I did try and most of them seem to be a bit cumbersome in the sense that they give the date modified of each file but I don't know if they can compare 2 dates. Plus when you have something like dir /od in DOS why would you want to write the code for the same thing. I wrote a following piece of code which is freezing maybe because it is a mapped drive...can anyone help me with this one.
dim comm
set fso = createobject("scripting.filesystemobject")
set objShell = createobject ("wscript.shell") comm = " dir h:\ /od | find " & chr(34) & "FoxAdapter" & chr(34)
set oExec = objShell.Exec("%comspec% /c " & comm)
Do While oExec.Status = 0 WScript.Sleep 100
Loop set opt = oexec.stdout
while not opt.atendofstream optline = opt.readline
I have tested your code on my machine here and it seems to work fine I have just changed teh criteria it looks for...
So a diffrent log name and on a diffrent drive name which was mapped and it works fine.
It does not freeze for me...
Possibly some form of network problem? Have you tried copying down the logs to your local machine and tried running it on there? This will determine if its either the script of the mapped drive causing the freezing issue you have described.
This is weird, my oexec.status is never becoming 1. So I calculated the time that it takes for the command to execute and then added wscript.sleep 15000 in stead of that shady oexec.status.
That has got me through but now I have come across a new problem.
my fso.opentextfile is giving error. Here is the relevant bit of code.
set fso = createobject("scripting.filesystemobject")
Its very difficult to say from the portion of code you pasted. Please post your entire script inside of [ code ] ... [ /code ] blocks.(without the spaces) That way it will look like this:
And if you do, we could probably see what is going wrong with your script.
However, to answer a previous question that you asked,
quote:
Of course I did try and most of them seem to be a bit cumbersome in the sense that they give the date modified of each file but I don't know if they can compare 2 dates. Plus when you have something like dir /od in DOS why would you want to write the code for the same thing.
Because sometimes it is a matter of resource management. if I have a script that I have to run 50 instances of on one box simultaneously, I don't want it shelling out all of the time, since it would eat up more ram. Also, there is a performance hit for shelling out to dos. However, there are times when it can save you tons of time and effort. For example, your problem. You want the last two filenames that contain a string.
I set it up so that you can change the sDir folder to any location, and the searchstring can be anything else that you want. i used the /b parameter so that you wouldn't have to deal with all that nasty date stuff. Since the /od parameter makes sure that they are in order from oldest to newest, you don't need to compare dates. just take the last two. Also, the command causes an extra line to show up in the output_temp.txt file. That is why I am using the UBound -1 and UBound - 2.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury