retromercial Posted August 28, 2009 Posted August 28, 2009 I am trying to delete a file using FileDelete("\\server\folder\file.txt"). But it doesn't seem to work. This is a share that is available to everybody and I can add and delete files at will. So, why won't Autoit delete the file like I tell it to? It can read text out of the file as well, so that path is correct. It does work if I use a local file, such as FileDelete("C:\file.txt"). Any ideas??
99ojo Posted August 28, 2009 Posted August 28, 2009 I am trying to delete a file using FileDelete("\\server\folder\file.txt"). But it doesn't seem to work. This is a share that is available to everybody and I can add and delete files at will. So, why won't Autoit delete the file like I tell it to? It can read text out of the file as well, so that path is correct. It does work if I use a local file, such as FileDelete("C:\file.txt"). Any ideas?? Hi, for debugging purpose try this code and post result: ;check wether you can write on share with autoit $testfile = "\\server\folder\file.txt" ; please change for your requirements $file = FileOpen($testfile, 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") ; If you see this msg, you can't write. If you can't write, you can't delete Exit EndIf ;Write into file something FileWrite($file, "Line1") FileWrite($file, "Still Line1" & @CRLF) FileWrite($file, "Line2") FileClose($file) ;now we try to delete created file If FileDelete ($testfile) = 1 Then MsgBox (0,"Successfully....","... delete!") Else MsgBox (0,"Error....","... deleting File!!!!!") EndIf ;-)) Stefan
retromercial Posted August 28, 2009 Author Posted August 28, 2009 (edited) I just don't get what I'm doing wrong. Your example works just fine. Mine doesn't. Code below: $keyfile1 = "\\server\public\apps\1.txt" $file = FileOpen($keyfile1, 1) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $licensekey=FileReadLine($keyfile1, 1) msgbox(0,"The key is...",$licensekey) fileclose($file) if filedelete($keyfile1)=1 Then msgbox(0,"YES","YES") Else msgbox(0,"NO","NO") EndIf _EDIT_ It works now. Edited August 28, 2009 by retromercial
retromercial Posted August 28, 2009 Author Posted August 28, 2009 So now my next problem is this... I have 110 text files. This script is set to delete the file it uses while it runs. How can I make it so that if it doesn't find a text file, it just moves on to the next one? Sorry, I'm completely new at this. Using the code above, how can I accomplish this? I thought about using a bunch of If statements, but that sounds lengthy... is there an easier way?
Bert Posted August 28, 2009 Posted August 28, 2009 ummm...fileexist? The Vollatran project My blog: http://www.vollysinterestingshit.com/
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now