Jump to content

How many different ways are there to delete a file? Can you show me a few more than just FileDelete?


Recommended Posts

I'm trying to delete "C:\OneDrive\PCRemoteControl\software.txt" a few seconds after it's created.

I have a program on one end create the file, and a program on another computer wait for that file to show up then read it's contents and delete it. The problem is, that doesn't work right away. I have to FileDelete in a loop until it can't find the text file anymore.

Yet, I can delete via right click>delete it the moment I see it show up in explorer.
Obviously there's a way to delete it right away, so I'm wanting to try a few other methods.
So, how many different ways would you delete "C:\OneDrive\PCRemoteControl\software.txt"?

Thanks all!

Edited by Draygoes
additon
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

  • 1 month later...
  • 11 months later...

Dear all

is there any way to save text file in OneDrive shared folder,

not my  account,

the folder shared with me.

i have used links but thy did not works.

FileWrite ("https://saudiairlines-my.sharepoint.com/:t:/g/personal/sbahwal_saudia_com/EQnrrPwDObBCo3wfD1qrlv8Bvob-vqxoyW7iRzdXCuCOZA?e=5amnxf"& "\"&  "TEST.txt",$Sarray )

 Thanks

Edited by samibb
Link to comment
Share on other sites

The reason propably is, that the file is still opened (locked), so you will need to investigate, when the file is not locked any more.

 

For files opened over the network this is possible with the use of this (just the function of a larger script to be able to replace opened files on SMB shares)

Func AbArbeiten($_Srv, $_Shr, $_fPth, $_fNme)

    Local $iID = 0
    Local $iRights = 1
    Local $iLckCount = 2
    Local $iFPFN = 3
    Local $iUser = 4

    ConsoleWrite($_fPth & $_fNme & @CRLF)

    Local $aFile = _Net_Share_FileEnum($_Srv)
    If IsArray($aFile) Then
        ; _ArrayDisplay($aFile)
        Local $x
        $ToolTxt = "Open File Handles:"
        $ToolTitle = "Handles to be checked total: " & $aFile[0][0]
        UpdateToolTip()
        AdlibRegister(UpdateToolTip, 1000)
        For $x = $aFile[0][0] To 1 Step -1
            $ToolTitle = $x & " handles remaining for checking..."

            If Not StringInStr($aFile[$x][$iFPFN], $_fPth & $_fNme) Then
                ; ConsoleWrite("Nix Enthalten in: " & $aFile[$x][$iFPFN] & @CRLF)
                _ArrayDelete($aFile, $x)
            Else
                $ToolTxt &= @CRLF & $aFile[$x][$iFPFN] & ", User = " & $aFile[$x][$iUser]
                ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToolTxt = ' & $ToolTxt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            EndIf
        Next
        $aFile[0][0] = UBound($aFile) - 1
        _ArraySort($aFile, 0, 1, 0, $iUser)
        ; _ArrayDisplay($aFile, $aFile[0][0] & " FileLocks found.")
        If $aFile[0][0] = 0 Then
            $ToolTitle = "Done, no open file handles were found"
            $ToolTxt &= @CRLF & ", no handles to be closed for this file!"
            Sleep(2000)
            $ToolTxt = ""
            ReplaceFile()
        Else
            $ToolTitle =  $aFile[0][0] & " open file handles were found..."
            $CloseErr = 0
            For $x = 1 To $aFile[0][0]
                If _Net_Share_FileClose($Server, $aFile[$x][$iID]) Then
                    $ToolTxt &= @CRLF & @TAB & "Handle closed: " & $aFile[$x][$iID]
                Else
                    $ToolTxt &= @CRLF & "ERROR: Handle Close Failed! --> " & $aFile[$x][$iFPFN] & ", User = " & $aFile[$x][$iUser]
                    $CloseErr += 1
                EndIf
            Next
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CloseErr = ' & $CloseErr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            If $CloseErr = 0 Then
                $ToolTitle = "All found open file handles could be closed."
                ReplaceFile()
            Else
                $ToolTitle = $CloseErr & " Handles could *NOT* be closed!"
                Sleep(2000)
            EndIf
            Sleep(1000)
            $ToolTxt = ""
            $ToolTitle = ""
        EndIf
    Else
        MsgBox(0, "not an array", $aFile & @CRLF & @error & @CRLF & @extended & @CRLF & _
                "Unable to retrieve the array of open file handles for " & $Share)
    EndIf
EndFunc   ;==>AbArbeiten

Func UpdateToolTip()
    ToolTip($ToolTxt, MouseGetPos(0) + 20, MouseGetPos(1) + 20, $ToolTitle)
    ; ConsoleWrite( $ToolTxt & @CRLF & $ToolTitle & @CRLF & "-------------------" & @CRLF)
EndFunc   ;==>UpdateToolTip

 

 

For files opened by the local OS on the local disk at least I'm not aware of a similar function in AutoIT, but these two tools proove, that it's technically possible to retrieve this information:

From NirSoft there is a GUI tool to do this: https://www.nirsoft.net/utils/opened_files_view.html

Another tool is unlocker by Cedrick Collomb: It's going to the context menu (rightclick-> unlock file), so it should be command line capable, that might help you.

Edited by rudi
added lines of func "updatetooltip"

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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