Sign in to follow this  
Followers 0
mrrlg

When The File Extension Isn't There

16 posts in this topic

I have pieced together this script to check a folder and e-mail users when files matching a certain date are found in the file. It currently works with a static date but I need to solve two problems. First I would like to change the FileGetTime portion to check for files modified on today's date.

#include <INet.au3>

;''Settings''
$folder = 'c:\lgeai\trio\';-- With trailing backslash
$filenames = '*.*';-- Wildcards accepted.
$WhatTime = 0;---0,1 or 2 as FileGetTime option
$y=2006
$m=04
$d=24;to select all files of the 04 24 2006 dd mm yyyy

;''Code''
$Handle = FileFindFirstFile($folder & $filenames)  
If $Handle = -1 Then
   MsgBox(0, "Error", "No files/directories matched the search pattern")
   Exit
EndIf

$c = 0
While 1
   $file = $folder & FileFindNextFile($Handle) 
   If @error Then ExitLoop

   $time = FileGetTime ( $file , $WhatTime )
   If $time[0] = $y AND $time[1] = $m AND $time[2] = $d Then
     $c = $c + 1

$s_SmtpServer = "10.X.X.X"
$s_FromName = "my name"
$s_FromAddress = "myname@sna.com"
$s_ToAddress = "yourname@sna.com"
$s_Subject = "FTP Files created"
Dim $as_Body[2]
$as_Body[0] = "ftp files were uploaded successfully"
$as_Body[1] = "Sent through SMTP"
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
$err = @error
If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
EndIf

  EndIf
WEnd
FileClose($Handle)

If $c = 0 Then MsgBox(0, "Error", "No files/directories matched the requested time.")

The second problem is with the files themselves. There are three files created. I get a successful email for the first two a .xls and .txt file. It errors on the third because it has no file extention. The file names themselves contain the date they were created and random characters as their file name. The only constant is the file extension. If I can solve the first I can live with the second by checking for one file extention and trusting that the other two files are there.

Share this post


Link to post
Share on other sites



maybe

$y = @YEAR
$m = @MON
$d = @MDAY


MsgBox (0, "date", @YEAR & "-" & @MON & "-" & @MDAY)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Actually juct changing

$y=2006
$m=04
$d=24

to

$y= @YEAR
$m= @MON
$d= @MDAY

has solved the first problem, but I received two error messages and only one successful email message to the recipients.

Also, is there a way to close the message boxes after a set period of time?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Also, is there a way to close the message boxes after a set period of time?

Straight from the helpfile:

MsgBox ( flag, "title", "text" [, timeout] )

Parameters

flag The flag indicates the type of message box and the possible button combinations. See remarks.

title The title of the message box.

text The text of the message box.

timeout [optional] Timeout in seconds. After the timeout has elapsed the message box will be automatically closed.

Edited by Simucal

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

Actually juct changing

$y=2006
$m=04
$d=24

to

$y= @YEAR
$m= @MON
$d= @MDAY

has solved the first problem,...

no... Duh!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Ouch! My apologies if I offended you by my reply. My comment was only that the message box was not necessary for the successful completion of that portion of the script.

I suspect that your comment is really the forum equivalent of "Valuater rises silently up over the edge of the cubicle and cocks a condescending eyebrow at the rest of the cubicle dwellers!" Consider me sufficiently chastised.

Share this post


Link to post
Share on other sites

Nice reply... mrrlg

My comment was only that the message box was not necessary for the successful completion of that portion of the script.

got it.. 8)

is everything working now?

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

The first portion of the script works perfectly and when I insert the message box it shows me that the three files I expect to be there are indeed there.

When I add on the email notification part I get these problems. It will generate a successful email for the two files that have file extentions but will generate an error message for the third file that has no file extention. Is there a way to generate only one successful message if any of the three files are found?

Share this post


Link to post
Share on other sites

maybe

If $Response = 1 Then
            If $c=2 Then MsgBox(0, "Success!", "Mail sent")
        Else
            If $c<3 MsgBox(0, "Error!", "Mail failed with error code " & $err)
        EndIf

if the two are sent... you will get one ok message

if the two error you will get an error message

if the third ( no ext) errors you will not be notified

in theory of-course

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted

This worked somewhat. I still received two successful emails and one notification on the server of the third email failing. The error code is 50.

If $Response = 1 Then
    If $c=2 Then MsgBox(0, "Success!", "Mail sent" , 5)
    Else
    If $c<3 Then MsgBox(0, "Error!", "Mail failed with error code " & $err, 5)
EndIf

Share this post


Link to post
Share on other sites

#11 ·  Posted

can you give the third file an "extention" of some kind?

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#12 ·  Posted

I wish I could but the files are generated by a SAP application that requires one of them to be configured in that fashion.

I supose I could change the script to just look for the .xls and .txt files and hope that the third one is there as well.

Share this post


Link to post
Share on other sites

#13 ·  Posted

When I run this as a .au3 script it works properly. When I convert it to an executable using 3.1 beta, it fails with three error messages (error code 50). What could be the problem? I am trying to run the executable as a scheduled task.

#include <INet.au3>

;''Settings''
$folder = 'c:\lgeai\trio\';-- With trailing backslash
$filenames = '*.*';-- Wildcards accepted.
$WhatTime = 0;---0,1 or 2 as FileGetTime option
$y= @YEAR
$m= @MON
$d= @MDAY 

;''Code''
$Handle = FileFindFirstFile($folder & $filenames)  
If $Handle = -1 Then
   MsgBox(0, "Error", "No files matched the search pattern")
   Exit
EndIf

$c = 0
While 1
   $file = $folder & FileFindNextFile($Handle) 
   If @error Then ExitLoop

   $time = FileGetTime ( $file , $WhatTime )
   If $time[0] = $y AND $time[1] = $m AND $time[2] = $d Then
     $c = $c + 1
;MsgBox (0, "date", @YEAR & "_" & @MON & "_" & @MDAY)
     
$s_SmtpServer = "10.X.X.X"
$s_FromName = "SNA Messenger"
$s_FromAddress = "snamessenger@sna.com"
$s_ToAddress = "snasapr@sna.com"
$s_Subject = "SAP FTP Upload"
Dim $as_Body[2]
$as_Body[0] = "SAP successfully uploaded files to SLC FTP."
$as_Body[1] = "This is an automated message"
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
$err = @error

If $Response = 1 Then
    If $c=2 Then MsgBox(0, "Success!", "Mail sent" , 5)
    Else
    If $c<3 Then MsgBox(0, "Error!", "Mail failed with error code " & $err, 5)
EndIf

  EndIf
WEnd
FileClose($Handle)

If $c = 0 Then MsgBox (0, "Error", "No files matched the requested time", 5)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

i compiled it and did not get any errors, however it doesnt function ( find any files )

can you post the actual error

8)

EDIT

I was able to get a mail faild code 3

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#15 ·  Posted

When I run the executable on the machine I created the script, it runs correctly. When I move it to the server I immediately get three gui errors "Mail failed with error code 50". This server has no mail client (Lotus Notes). I then tried this on a server with a mail client and got the same errors. I even moved it to another machine that has my mail client on it and I also received the same three errors. Could it be that there is a file or files from AutoIt itself that are being called when the script is running?

Share this post


Link to post
Share on other sites

#16 ·  Posted

Could it be that there is a file or files from AutoIt itself that are being called when the script is running?

i dont think the problem is autoit files...

maybe your location of

'c:\lgeai\trio\'

????

more-so, it could be a server, rights, etc problem...

not my area, sorry

8)


NEWHeader1.png

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