Draygoes Posted April 11, 2022 Share Posted April 11, 2022 (edited) 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 April 11, 2022 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 More sharing options...
ad777 Posted April 11, 2022 Share Posted April 11, 2022 (edited) you can use: FileDelete ( "C:\OneDrive\PCRemoteControl\software.txt" ) OR: #include <WinAPIFiles.au3> _WinAPI_DeleteFile ( "C:\OneDrive\PCRemoteControl\software.txt") Edited April 11, 2022 by ad777 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
Bitnugger Posted May 12, 2022 Share Posted May 12, 2022 FileRecycle( "C:\OneDrive\PCRemoteControl\software.txt") ; Move file to trashcan. Link to comment Share on other sites More sharing options...
samibb Posted April 29, 2023 Share Posted April 29, 2023 (edited) 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 May 4, 2023 by samibb Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2023 Developers Share Posted April 30, 2023 One place for your question is enough.. other post removed. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
samibb Posted April 30, 2023 Share Posted April 30, 2023 Sorry for that. Thanks Link to comment Share on other sites More sharing options...
Lepes Posted April 30, 2023 Share Posted April 30, 2023 (edited) Well... I Think you don't need different ways to delete a file. You need to be notified when a file is created, then you can delete it.https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_FindFirstChangeNotification.htm Look examples on the helpFile. Cheers! Edited April 30, 2023 by Lepes Zedna 1 Link to comment Share on other sites More sharing options...
argumentum Posted April 30, 2023 Share Posted April 30, 2023 (edited) . Edited April 30, 2023 by argumentum oops Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
rudi Posted May 4, 2023 Share Posted May 4, 2023 (edited) 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) expandcollapse popupFunc 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 May 4, 2023 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 More sharing options...
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