Jump to content

Problem with script containing FileDelete function


Recommended Posts

In the following script, why does the script work fine when the FileDelete function is remarked out, yet fail with a Notepad "Cannot find the ... file" error dialog box when the function is included? (see attachment) It seems the deletion part works, but I can't figure out why and how to cope with the error dialog box that appears ONLY when the FileDelete function is enabled. (I unsuccessfully tried scripting the closing of the dialog.) It's probably something very simple that I'm overlooking, but, for the life of me, I'm currently stumped! Thanks in advance for your thoughts and insights!

Harvey

#include <GUIConstants.au3>
#include <IE.au3>
#include <File.au3> ; for _FilePrint function

$sFileName = "C:\$$$tmpfile$$$.txt"
;
$file = FileOpen($sFileName, 2) ; open file to erase previous contents
FileWriteLine($file, "some text here")
FileWriteLine($file, "")
FileClose($file)
;
; reformat some data here and append to file:
$tmp = "some more data here"
$file = FileOpen($sFileName, 1) ; open file for appending
FileWriteLine($file, $tmp)
FileClose($file)
;
MsgBox(0,"","Check existence of C:\$$$tmpfile$$$.txt now" & Chr(10) & "BEFORE clicking OK button")
;
$nPrintSuccess = _FilePrint($sFileName)
If $nPrintSuccess Then
;$nDeleteSuccess = FileDelete($sFileName) ; <----------
Else
    MsgBox(0,"","call DisplayPrintProblemMsg()")
EndIf

post-10198-1167861146_thumb.jpg

Link to comment
Share on other sites

Try this code using ShellExecuteWait.

#include <GUIConstants.au3>
#include <IE.au3>
;~ #include <File.au3> ; for _FilePrint function

$sFileName = "C:\$$$tmpfile$$$.txt"
;
$file = FileOpen($sFileName, 2) ; open file to erase previous contents
If $file <> -1 Then
    FileWriteLine($file, "some text here")
    FileWriteLine($file, "")
    FileClose($file)
    ;
    ; reformat some data here and append to file:
    $tmp = "some more data here"
    $file = FileOpen($sFileName, 1) ; open file for appending
    If $file <> -1 Then
        FileWriteLine($file, $tmp)
        FileClose($file)
    EndIf
Else
    Exit 1
EndIf
;
MsgBox(0, "", "Check existence of C:\$$$tmpfile$$$.txt now" & @CRLF & "BEFORE clicking OK button")
;
$nPrintSuccess = ShellExecuteWait ($sFileName, '', '', 'print')
If $nPrintSuccess = 0 Then
    $nDeleteSuccess = FileDelete($sFileName) ;    <----------
Else
    MsgBox(0, "", "call DisplayPrintProblemMsg()")
EndIf

:P

Link to comment
Share on other sites

In the following script, why does the script work fine when the FileDelete function is remarked out, yet fail with a Notepad "Cannot find the ... file" error dialog box when the function is included? (see attachment) It seems the deletion part works, but I can't figure out why and how to cope with the error dialog box that appears ONLY when the FileDelete function is enabled. (I unsuccessfully tried scripting the closing of the dialog.) It's probably something very simple that I'm overlooking, but, for the life of me, I'm currently stumped! Thanks in advance for your thoughts and insights!

The problem is:

_FilePrint() uses Notepad.exe (or whatever editor is your default) to print the file via ShellExecute. Now, if you delete

the file BEFORE the editor gets started you will get the error message, that the file was not found. Just wait a few seconds

(sleep(3000)) and the file should be printed.

#include <File.au3>

$sFileName = "C:\tempfile.txt"
FileWriteLine("c:\tempfile.txt", "Hello Test")

$nPrintSuccess = _FilePrint($sFileName)
Sleep(3000); <<== WITHOUT the sleep, the file gets deleted BEFORE the editor can open it!
$nDeleteSuccess = FileDelete($sFileName)

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...