Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


find the last modified file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,53825
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> find the last modified file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 find the last modified file - 11/26/2007 5:13:25 PM   
  avkuvalekar

 

Posts: 13
Score: 0
Joined: 11/8/2007
Status: offline
Hi,

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.

Thanks! :)
 
 
Post #: 1
 
 RE: find the last modified file - 11/27/2007 2:04:50 AM   
  dm_4ever


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.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to avkuvalekar)
 
 
Post #: 2
 
 RE: find the last modified file - 11/27/2007 7:59:56 PM   
  avkuvalekar

 

Posts: 13
Score: 0
Joined: 11/8/2007
Status: offline
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

wend

msgbox optline

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: find the last modified file - 11/27/2007 9:46:20 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
I would think a regexp would work, but I am hopeless at writing them

_____________________________

"You start coding. I'll go find out what they want."

(in reply to avkuvalekar)
 
 
Post #: 4
 
 RE: find the last modified file - 11/27/2007 10:32:24 PM   
  morpheus83uk

 

Posts: 379
Score: 0
Joined: 8/21/2006
Status: offline
Hello,

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.

Many Thanks

James

(in reply to gdewrance)
 
 
Post #: 5
 
 RE: find the last modified file - 11/28/2007 12:20:50 PM   
  avkuvalekar

 

Posts: 13
Score: 0
Joined: 11/8/2007
Status: offline
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")



f_name_new = "F:\" & f_name & "txt"

f_name = "h:\" & f_name & "log"
fso.CopyFile f_name, f_name_new , overwriteexisting

do

wscript.sleep 500
if fso.FileExists(f_name_new) then

flag = 1
end if
loop
while flag = 0
msgbox f_name_new

set
ts = fso.OpenTextFile(f_name_new , ForReading)
counter = 0

It gives a runtime error saying "invalid procedure or call argument" for the line
set ts = fso.OpenTextFile(f_name_new , ForReading)

what's wrong with this call??

Thanks!

(in reply to gdewrance)
 
 
Post #: 6
 
 RE: find the last modified file - 11/28/2007 4:52:05 PM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
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

(in reply to avkuvalekar)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> find the last modified file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts