Jump to content

filedelete will not work with 1 file


Recommended Posts

I have tried everything the path is correct, other files will delete but not this one

$file1 = ("C:\Nod32OD\defs.txt")

FileOpen($file1,0)

$noddefs = FileReadLine($file1)

FileClose($file1)

FileDelete($file1)

FileDelete("C:\Nod32OD\nod*.*")

FileDelete("C:\Nod32OD\defs.txt")

FileDelete("C:\Nod32OD\image0012.jpg")

I have even tried it twice any ideas

Link to comment
Share on other sites

  • Moderators

I have tried everything the path is correct, other files will delete but not this one

$file1 = ("C:\Nod32OD\defs.txt")

FileOpen($file1,0)

$noddefs = FileReadLine($file1)

FileClose($file1)

FileDelete($file1)

FileDelete("C:\Nod32OD\nod*.*")

FileDelete("C:\Nod32OD\defs.txt")

FileDelete("C:\Nod32OD\image0012.jpg")

I have even tried it twice any ideas

Have you checked to make sure that no instance of the file is still running/open? FileDelete() will not work if there is.

If you say yes, what return do you get when you check the status of the FileDelete() itself? Worse case you might try FileMove() ... name it something else, and then try FileDelete().

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

looks like even though I have closed it autoit still keeps it locked even though I close it. once the script finishes I can delete the file. I already have this at the end of my script to selfdelete I am not sure how to ad a second file

Func OnAutoItExit()

;following code causes script to delete itself

Local $sCmdFile

FileDelete("C:\Nod32OD\nod*.*")

FileDelete("C:\Nod32OD\image0012.jpg")

FileDelete(@TempDir & "\Scratch.bat")

$sCmdFile = ':loop' & @CRLF & 'del "' & @ScriptFullPath & '"' & @CRLF &'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF & 'del ' & @TempDir & '\Scratch.bat'

FileWrite(@TempDir & "\Scratch.bat", $sCmdFile)

Run(@TempDir & "\Scratch.bat", @TempDir, @SW_HIDE)

EndFunc

Link to comment
Share on other sites

I'm wondering why you would have to delete portions of NOD32 when it has an inbuilt uninstall facility, unless there are malicious intentions? If the anti-virus software is still running, you would have to (politely) ask it to terminate itself before deleting it, wouldn't you?

Link to comment
Share on other sites

Something I always do when trying to delete a file...

Global $g_Dir

$g_Dir = "C:\Nod32OD\"

_RemoveFile("defs.txt")

Func _RemoveFile($del_file)
    Local $confirm = "", $i = 0
    
    FileChangeDir($g_Dir)
    $confirm = MsgBox(4, "WARNING!", "You are about to delete: " & @CRLF & $del_file & @CRLF & "Are you sure you want to continue?")
    If $confirm = 6 Then
        For $i = 0 To 10 Step 1
            FileDelete($del_file)
            Sleep(250)
            If FileExists($del_file) Then
                ContinueLoop
            Else
                Return
            EndIf
        Next
        MsgBox(0, "ERROR", "File: " & $del_file & "has not been deleted. Please remove the file manually.")
    EndIf   
EndFunc

See if that works... It should, if not then another part of your script is messed up.

I hope it helps,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Looks like Larry is right. I'll point it out more clearly. Close the handle to FileOpen.

$file1 = ("C:\Nod32OD\defs.txt")

$handle = FileOpen($file1,0) ; Open handle

$noddefs = FileReadLine($handle) ; Use handle

FileClose($handle) ; Close handle

FileDelete($file1)

FileDelete("C:\Nod32OD\nod*.*")

FileDelete("C:\Nod32OD\defs.txt")

FileDelete("C:\Nod32OD\image0012.jpg")

:D
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...