Jump to content

FileDelete Problem


Recommended Posts

v 3.2.2.0

Not sure if it's a "BUG", but I've noticed that when a file is opened in write mode (1 or 2) using the FileOpen function, even after you close the file, you cannot use FileDelete to remove it. Open it in Read mode only, and it works fine

Ex:

$file1 = "C:\temp.txt"

FileOpen($file1, 1)

FileClose($file1)

If FileExists($file1) Then

FileDelete($file1)

EndIf

Doesn't work for me even if I use absolute paths, or close the file multiple times, or sleep between FileClose and FileDelete. Doesn't return an error, just won't do what I ask. More than likely, I am just doing something wrong.

Thanks,

Chris

Link to comment
Share on other sites

  • Moderators

FileClose() needs a handle from FileOpen().

$file1 = "C:\temp.txt"
$handle = FileOpen($file1, 1)
FileClose($handle)
If FileExists($file1) Then
    FileDelete($file1)
EndIf
Edited by SmOke_N

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

  • Moderators

That's why I'm a noob. Thanks,

Chris

No worries... I'll be honest though, you don't see many that have used AutoIt for a while setup a conditional statement for FileDelete(), I guess it isn't really necessary, but I like the idea that you are using conditional statements in just the short snippet you provided, makes me think you will also implement error checking at some time... And that's always a good thing.

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

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