Sign in to follow this  
Followers 0
retromercial

Delete file on network share

5 posts in this topic

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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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. :D

Edited by retromercial

Share this post


Link to post
Share on other sites

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?

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