Sign in to follow this  
Followers 0
k3dlg

Newbie looking for direction and help

7 posts in this topic

#1 ·  Posted (edited)

I'm working on a utility that will list files newest first, and marks files listed after a user designated time. What I have to date is basically a cut and paste of different parts of scripts I have found here and over the web. The problem I'm running into is that it stopped marking the files after the designated time. I've poked around but haven't gotten too far. Any advise and direction is greatly welcomed, and I also welcome thoughts and ideas on making everything from the programing its self to the user inputs and displays work and look better. Attached is a moddified array.au3 that I edited to make the script work, and 2 screen shots 1 of the user input and results I'm getting.

Go easy on me, the last time I did programming a mouse was still just a rodent.

Thank you all very much for your time!

73 de K3DLG

Derrick

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Language=1033
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <Array123.au3>
#include <file.au3>
#include <GuiListView.au3>
#include <date.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
;##############
;includes
;##############
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Last File Utility", 350, 300, 192, 122)
$Input1 = GUICtrlCreateInput("", 120, 20, 121, 24)
$Input2 = GUICtrlCreateInput("", 120, 70, 121, 24)
$Input3 = GUICtrlCreateInput("", 120, 130, 121, 24)
$Button1 = GUICtrlCreateButton("Continue", 250, 200, 75, 25)
$Label1 = GUICtrlCreateLabel("Job Name", 40, 20, 70, 20)
$Label2 = GUICtrlCreateLabel("Last File", 40, 70, 75, 20)
$Label3 = GUICtrlCreateLabel("AM or PM", 40, 130, 60, 20)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$sName1 = GUICtrlRead($Input1)
$sName2 = GUICtrlRead($Input2)
$sName3 = GUICtrlRead($Input3)
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $Button1
   $jobname = $sName1
   $lasttime = $sName2
   $ampm = $sName3
   GUIDelete()
   ExitLoop
EndSwitch
WEnd
;#####################################
;********NEED TO MAKE INPUTS FOR THESE
$jobname = $jobname
$lastpagetime = $lasttime & $ampm
;*************
;#################################
Func _Time_ConvertTo24($s_Str)
If Not StringRegExp($s_Str, "^(?i)\d+.*:.*\d+\s*[ap]m$") Then Return $s_Str
Local $aHold = StringRegExp($s_Str, "(\d+):(\d+)", 1), $sRtn, $sHour
If @error Then Return SetError(1)
;$aHold[0] = StringFormat("%02s", $aHold[0])
If StringRegExp($s_Str, "(?i)^.+pm$") Then
  $sHour = $aHold[0]
  $sHour = $sHour + 12
  If $sHour = 24 Then $sHour = 0
Else
  $sHour = $aHold[0]
  If $sHour = 12 Then $sHour = 0
  $sRtn = $sHour & $aHold[1]
EndIf
Return StringFormat("%02u", $sHour) & $aHold[1]
EndFunc   ;==>_Time_ConvertTo24
$lastpage24 = _Time_ConvertTo24($lastpagetime)
$lthour = StringMid($lastpage24, 1, 2)
$ltmin = StringMid($lastpage24, 3, 2)
$nametest = StringMid($jobname, 1, 2)
$dayinfo = StringMid($jobname, 5, 2)
$driveletter = "p:\"
If $nametest = "pt" Then
$driveletter = "t:\"
EndIf
$r = fastwrapdir($driveletter & $jobname & "*.*")
$datefull = StringMid($jobname, 3, 4)
$datemonth = StringMid($jobname, 3, 2)
$dateday = StringMid($jobname, 5, 2)
$makedate = @YEAR & "/" & $datemonth & "/" & $dateday

$maketime = $lthour & ":" & $ltmin
$lastfiletime = $makedate & " " & $maketime & ":00"
Func fastwrapdir($patterns)
$result = ""
$pid = Run("cmd /cdir " & $patterns & " /B /S /A:H /A:S /A:-D", "", 0, 6)
While 1
  $result &= StdoutRead($pid)
  If @error Then ExitLoop
WEnd
$ar = StringSplit($result, @CRLF, 1)
$ar[0] -= 1
Return ($ar)
EndFunc   ;==>fastwrapdir
Global $aArray = $r
Global $aArray2D[10][2]
ReDim $aArray2D[$aArray[0] + 1][8]
$aArray2D[0][0] = $aArray[0]
Global $number = 0
For $z = 1 To $r[0]
$t = FileGetTime($r[$z], 0)
$yyyymd = $t[1] & "/" & $t[2]
$hhmm = $t[3] & ":" & $t[4]
$datetime = $t[0] & "_" & $t[1] & "_" & $t[2] & "_" & $t[3] & ":" & $t[4]
$aArray2D[$z][4] = $datetime
$aArray2D[$z][0] = $aArray[$z]
$aArray2D[$z][1] = $yyyymd
;$aArray2D[$z][2] = $hhmm
$hour = $t[3]
$ampm = 'AM';
If $hour >= 12 Then
  $ampm = 'PM';
  If $hour > 12 Then
   $hour = $hour - 12;
  EndIf
ElseIf $hour = 0 Then
  $hour = 12;
EndIf
$hhmm2 = $hour & ":" & $t[4] & " " & $ampm
$aArray2D[$z][2] = $hhmm2
$sRET = _DateAdd("n", -30, $lastfiletime)
$stimeadj = StringMid($sRET, 12, 5)
$sdateadj = StringMid($sRET, 9, 2)
$smonthadj = StringMid($sRET, 6, 2)
$syearadj = StringMid($sRET, 1, 4)
$dayinfoa = $sdateadj

If $datetime >= $syearadj & "_" & $smonthadj & "_" & "0"&$dayinfoa-1 & "_" & $stimeadj Then
  $aArray2D[$z][3] = "*"
  $number = $number + 1
EndIf
$aArray2D[0][3] = $number
Next
_ArraySort($aArray2D, 1, 1, "", 4)
_ArrayDisplay123($aArray2D)

NOTE: I corrected the Array file to the correct one I have been working with. Sorry if this caused any problems.

results.pdf

userinput.pdf

Array123.au3

Edited by k3dlg

73 de K3DLGDerrick

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have a problem understanding this.

If this is true:

I'm working on a utility that will list files newest first, and marks files listed after a user designated time.

and this is true:

The problem I'm running into is that it stopped marking the files after the designated time.

then you should not have got any results at all. edit perhaps I'm just not understanding you.

I looked at the code but I couldn't quite figure out how you expect it to work. I imagine you want it to list files created between a designated time up to the present. Could you clarify exactly what you want the script to do. I also suggest adding comments to your code to make it easier to understand. Your code can be simplified and better organized in several ways.

Edited by czardas

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

By the looks of the results PDF you have uploaded, it is showing all files?

How many files are in the directory?

Also, looking at your user input, you do not allow for a date.

Edited by Mikeman27294

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yes and how far back should it go? Should it return all files prior to the designated time without marking them? What if the designated time is in the future? Perhaps there is some logic there. Anyway it's not clear to me yet.

Edited by czardas

Share this post


Link to post
Share on other sites

Sorry for the delay in getting back to you all.

Lets see if I can explain this better and answer some of your questions.

The utility is designed to search a whole drive for the name of the file inputted.(lr0124)

The file time changes depending on the files being searched. It is also used to reference what files came in 30 minutes before and all files after the time that has been inputted. This is for monitoring traffic.(9:35 & pm)

The final display is of all files, regardless of their time as they are searched by name not time, on the drive that have the name that was inputted. The files are listed newest to oldest. The column marked "last 30 minutes" marks all files that came in after a set time. In this case the input is 9:35pm and all files listed after (9:35pm - 30 minutes) 9:05pm are the only files that should have a star.

The date is taken from the file name.

Number of files in the directory can vary 5-150 is not unusual.

Hope this helps a little. I'll do my best to respond to everyone.

73 de K3DLG

Derrick


73 de K3DLGDerrick

Share this post


Link to post
Share on other sites

Update:

I ran the utility today and things worked as I wanted them to. I think this means that I have something set wrong with the usage of the date. Attached is an example of what the results should look like. Highlighted are the pages that are within the time frame (9:35pm - 30 minutes= 9:05pm).

I guess right off the bat I think I need help with working with date and time information with the files. The code below is where I think I might be making my mistakes with the file time comparisons. I know I struggled quite a while making this work in the first place. So I think right now( subject to change :) ) I need advice and direction on what the best and simplest way to compare file times would be.

Thank you much!

$hhmm2 = $hour & ":" & $t[4] & " " & $ampm
$aArray2D[$z][2] = $hhmm2
$sRET = _DateAdd("n", -30, $lastfiletime)
$stimeadj = StringMid($sRET, 12, 5)
$sdateadj = StringMid($sRET, 9, 2)
$smonthadj = StringMid($sRET, 6, 2)
$syearadj = StringMid($sRET, 1, 4)
$dayinfoa = $sdateadj
If $datetime >= $syearadj & "_" & $smonthadj & "_" & "0"&$dayinfoa-1 & "_" & $stimeadj Then
  $aArray2D[$z][3] = "*"
  $number = $number + 1
EndIf
$aArray2D[0][3] = $number
Next

Working example of final results:

post-69734-0-92436500-1328228476_thumb.j


73 de K3DLGDerrick

Share this post


Link to post
Share on other sites

Quick copy of a note. I did change the array file attached in te original post to the one I have been using. Sorry if this caused any problems.


73 de K3DLGDerrick

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