Sign in to follow this  
Followers 0
avprerunners

Help - Im New To Autoit And Have A Question

7 posts in this topic

Hi all,

Im new to autoit (just started learning it last week)..any how ive searched High and Low for 3 days now trying to figure out how to do the following:

I need to search all of drive c: and drive h: (it cant search other drives) for all files with a certain name (in.mbx). Once i have all the files i need to get the PATH of the Newest (last modified) Version of (in.mbx) and set that path as a Varaible that i can use later in my script

I am using the newest beta of autoit 3.

Thanks in advance for any help =)

Brandon

Share this post


Link to post
Share on other sites



Been there tryed that..I saw all that stuff but i cant figure out how to make it all work togather..Below is good if i could make it do recursive of C: as well as H:..This code finds the newest as well as gets me the path of the newest file.

#include <GUIConstants.au3>

#Include <File.au3>

#Include <Array.au3>

$folder = 'c:\'

$search = FileFindFirstFile($folder & "*.txt")

$now = 0

$newest = ""

While 1

$file = FileFindNextFile($search)

if @error Then ExitLoop

if FileGetTime($folder & $file,0,1) > $now Then

$now = FileGetTime($folder & $file,0,1)

$newest = $folder & $file

EndIf

WEnd

MsgBox(0,"Newest",$newest & " is your newest file, created : " & $now)

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>
$folder = 'c:\'
$search = FileFindFirstFile($folder & "*.txt")
$now = 0 
$newest = ""
While 1
$file = FileFindNextFile($search)
if @error Then ExitLoop
if FileGetTime($folder & $file,0,1) > $now Then 
$now = FileGetTime($folder & $file,0,1)
$newest = $folder & $file
EndIf
WEnd
$folder = "h:\"
$search = FileFindFirstFile($folder & "*.txt")
While 1
$file = FileFindNextFile($search)
if @error Then ExitLoop
if FileGetTime($folder & $file,0,1) > $now Then 
$now = FileGetTime($folder & $file,0,1)
$newest = $folder & $file
EndIf
Wend
MsgBox(0,"Newest",$newest & " is your newest file, created : " & $now)

This???

#)

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>
$folder = 'c:\'
$search = FileFindFirstFile($folder & "*.txt")
$now = 0 
$newest = ""
While 1
$file = FileFindNextFile($search)
if @error Then ExitLoop
if FileGetTime($folder & $file,0,1) > $now Then 
$now = FileGetTime($folder & $file,0,1)
$newest = $folder & $file
EndIf
WEnd
$folder = "h:\"
$search = FileFindFirstFile($folder & "*.txt")
While 1
$file = FileFindNextFile($search)
if @error Then ExitLoop
if FileGetTime($folder & $file,0,1) > $now Then 
$now = FileGetTime($folder & $file,0,1)
$newest = $folder & $file
EndIf
Wend
MsgBox(0,"Newest",$newest & " is your newest file, created : " & $now)

This???

#)

No that still dosent do recursive(all of c: and all oh H: and then find the newest file)

I do appreachate the help tho..this stuff is stumping me...lol

Brandon

Share this post


Link to post
Share on other sites

Func _FindRecursiveNewest($folder, $filetype)
   Local $search = FileFindFirstFile($folder&"\"&$filetype)
   Local $now, $newest
   If $search = -1 Then Return "NONE"
   While 1
      $file = FileFindNextFile($search)
      if @error Then ExitLoop
      if FileGetTime($folder & $file,0,1) > $now Then 
         $now = FileGetTime($folder & $file,0,1)
         $newest = $folder & $file
      EndIf
      If StringInString(FileGetAttrib($folder&$file), "D") And (not stringInString($file, ".."))Then
         $result = _FindRecursiveNewest($folder&$file&"\", $filetype)
         If $result <> "NONE" THen
            If $result[0] > $now Then
               $now = $result[0]
               $newest = $result[1]
            Endif
         EndIf
      Endif
   Wend
   Local $ret[2]
   $ret[0] = $now
   $ret[1] = $newest
   return $ret
EndFunc


$c_dir = _FindRecursiveNewest("C:\", "*.txt")
$h_dir = _FindRecursiveNewest("H:\", "*.txt")
msgBox(0, $c_dir[1], $c_dir[0])
msgBox(0, $h_dir[1], $h_dir[0])

#)

Share this post


Link to post
Share on other sites

Func _FindRecursiveNewest($folder, $filetype)
   Local $search = FileFindFirstFile($folder&"\"&$filetype)
   Local $now, $newest
   If $search = -1 Then Return "NONE"
   While 1
      $file = FileFindNextFile($search)
      if @error Then ExitLoop
      if FileGetTime($folder & $file,0,1) > $now Then 
         $now = FileGetTime($folder & $file,0,1)
         $newest = $folder & $file
      EndIf
      If StringInString(FileGetAttrib($folder&$file), "D") And (not stringInString($file, ".."))Then
         $result = _FindRecursiveNewest($folder&$file&"\", $filetype)
         If $result <> "NONE" THen
            If $result[0] > $now Then
               $now = $result[0]
               $newest = $result[1]
            Endif
         EndIf
      Endif
   Wend
   Local $ret[2]
   $ret[0] = $now
   $ret[1] = $newest
   return $ret
EndFunc
$c_dir = _FindRecursiveNewest("C:\", "*.txt")
$h_dir = _FindRecursiveNewest("H:\", "*.txt")
msgBox(0, $c_dir[1], $c_dir[0])
msgBox(0, $h_dir[1], $h_dir[0])

#)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0