Nunos Posted September 19, 2018 Share Posted September 19, 2018 #RequireAdmin #include <WindowsConstants.au3> #include <FileConstants.au3> $sFilePath = @HomeDrive & "\zoek_results.log" If FileExists($sFilePath) Then FileDelete($sFileZoekLog) If @error = 0 Then MsgBox(0, "0", $sFileZoekLog & " was removed.") ElseIf @error = 1 Then ; MsgBox(0, "1", $sFileZoekLog & "was not removed.") EndIf Else MsgBox(0, "Error Code", "The error code is: " & @error) EndIf As part of my script I need to delete this file C:\zoek_results.log I have tried modifying the above over and over but always the same I get the MsgBox Error Code and it is 0. I looked at the set attributes but I don't know what to set it to and none of the attributes I attempted to change worked. What am I missing? Link to comment Share on other sites More sharing options...
careca Posted September 19, 2018 Share Posted September 19, 2018 Im confused, what is $sFileZoekLog ? You mention a msgbox and the code 0, but isn't that from fileexists instead of filedelete? FrancescoDiMuro 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 19, 2018 Share Posted September 19, 2018 (edited) @Nunos FileDelete() does not return any @error code, so it is always be 0. Try to check the return value of the function. If FileDelete(YourFile) Then ConsoleWrite("File deleted successfully." & @CRLF) Else ConsoleWrite("Error while deleting the file." & @CRLF) EDIT: As @careca said, that variable in the FileDelete() function seems to not containing the file path to delete. Edited September 19, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Nunos Posted September 19, 2018 Author Share Posted September 19, 2018 (edited) 4 minutes ago, careca said: Im confused, what is $sFileZoekLog ? You mention a msgbox and the code 0, but isn't that from fileexists instead of filedelete? Oh that is what I had changed the $sFilePath from and too back and forth in various tests trying to see what I am doing wrong So $sFilePath should be $sFileZoekLog As far as the @error I guess I don't know I thought it was the return from FileDelete() ? Edited September 19, 2018 by Nunos Link to comment Share on other sites More sharing options...
Nunos Posted September 19, 2018 Author Share Posted September 19, 2018 16 minutes ago, FrancescoDiMuro said: @Nunos FileDelete() does not return any @error code, so it is always be 0. Try to check the return value of the function. If FileDelete(YourFile) Then ConsoleWrite("File deleted successfully." & @CRLF) Else ConsoleWrite("Error while deleting the file." & @CRLF) Okay I tried below. #RequireAdmin #include <WindowsConstants.au3> #include <FileConstants.au3> _RMVZOEKLOG() Func _RMVZOEKLOG() $sFileZoekLog = @HomeDrive & "\zoek_results.log" If FileDelete($sFileZoekLog) Then ConsoleWrite("File deleted successfully." & @CRLF) Else ConsoleWrite("Error while deleting the file." & @CRLF) EndIf EndFunc ;==>_RMVZOEKLOG and the console says. --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop Error while deleting the file. +>14:41:05 AutoIt3.exe ended.rc:0 +>14:41:05 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.003 So what do I need to do to actually delete the file? Link to comment Share on other sites More sharing options...
Danp2 Posted September 19, 2018 Share Posted September 19, 2018 So, the file resides in the root directory of the home drive? If not, then what is the full path to the file? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nunos Posted September 19, 2018 Author Share Posted September 19, 2018 @Danp2 Yes it is C:\zoek_results.log on this system but there are times when the HomeDrive is not C: on some systems so I was trying to address that with the @HomeDrive call. Link to comment Share on other sites More sharing options...
Danp2 Posted September 19, 2018 Share Posted September 19, 2018 Ok... just wanted to be sure. Could it be a rights issue? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Simpel Posted September 19, 2018 Share Posted September 19, 2018 Hi. What says ConsoleWrite($sFileZoekLog & @CRLF) and ConsoleWrite(FileExists($sFileZoekLog) & @CRLF)? Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Nunos Posted September 19, 2018 Author Share Posted September 19, 2018 6 minutes ago, Danp2 said: Ok... just wanted to be sure. Could it be a rights issue? It could be but I did #RequireAdmin at top of script. Link to comment Share on other sites More sharing options...
Nunos Posted September 19, 2018 Author Share Posted September 19, 2018 5 minutes ago, Simpel said: Hi. What says ConsoleWrite($sFileZoekLog & @CRLF) and ConsoleWrite(FileExists($sFileZoekLog) & @CRLF)? Simpel #RequireAdmin #include <WindowsConstants.au3> #include <FileConstants.au3> Func _RMVZOEKLOG() $sFileZoekLog = @HomeDrive & "\zoek_results.log" If FileDelete($sFileZoekLog) Then ConsoleWrite("File deleted successfully." & @CRLF) Else ConsoleWrite("Error while deleting the file." & @CRLF) EndIf EndFunc ;==>_RMVZOEKLOG $sFileZoekLog = @HomeDrive & "\zoek_results.log" ConsoleWrite($sFileZoekLog & @CRLF) ConsoleWrite(FileExists($sFileZoekLog) & @CRLF) --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop C:\zoek_results.log 0 +>15:10:22 AutoIt3.exe ended.rc:0 +>15:10:22 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.8142 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 20, 2018 Share Posted September 20, 2018 @Nunos Does deleting the file manually work? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
careca Posted September 20, 2018 Share Posted September 20, 2018 FileExists = 0? this is weird and im out of ideas. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Simpel Posted September 20, 2018 Share Posted September 20, 2018 Strange. Can you "Shift"-Rightclick the logfile and copy path and then declare $sFileZoekLog directly with that copied path (and ConsoleWrite it)? Maybe there is a special character hidden (or a space)? ConsoleWrite($sFileZoekLog & "--" & @CRLF) to see if there is a hidden space or: #include <Array.au3> Local $sFileZoekLog = ; paste with STRG+V the path you copied via Shift+Rightclick ; Convert the string to an ASCII array. Local $aArray = StringToASCIIArray($sFileZoekLog) ; Display the array to see that it contains the ASCII values for each character in the string. _ArrayDisplay($aArray) to see if there is possibly a strange character inside. Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Nunos Posted September 20, 2018 Author Share Posted September 20, 2018 12 hours ago, FrancescoDiMuro said: @Nunos Does deleting the file manually work? Yes I can manually delete the file but I do receive what I believe to be a user account control prompt. I am running the script with #RequireAdmin and using a local administrator account. 9 hours ago, careca said: FileExists = 0? this is weird and im out of ideas. I am confused about it as well. I am thinking it must be a permissions issue but I don't know how to solve it. 4 hours ago, Simpel said: Strange. Can you "Shift"-Rightclick the logfile and copy path and then declare $sFileZoekLog directly with that copied path (and ConsoleWrite it)? Maybe there is a special character hidden (or a space)? ConsoleWrite($sFileZoekLog & "--" & @CRLF) to see if there is a hidden space or: #include <Array.au3> Local $sFileZoekLog = ; paste with STRG+V the path you copied via Shift+Rightclick ; Convert the string to an ASCII array. Local $aArray = StringToASCIIArray($sFileZoekLog) ; Display the array to see that it contains the ASCII values for each character in the string. _ArrayDisplay($aArray) to see if there is possibly a strange character inside. Simpel I will try this now and report back but I have tried it with a file I made on the desktop with other names and copy pasted to the C: drive and then used the rename cmd to get the file name for the script to make sure I wasn't missing keys. Link to comment Share on other sites More sharing options...
Nunos Posted September 20, 2018 Author Share Posted September 20, 2018 @Simpel Here are the results. Link to comment Share on other sites More sharing options...
kaisies Posted September 20, 2018 Share Posted September 20, 2018 (edited) #requireadmin breaks console writes unless you launch scite as admin (which then, #requireadmin isn't needed). Where are these consolewrites copy+paste coming from? Are you launching scite as admin? #RequireAdmin #include <WindowsConstants.au3> #include <FileConstants.au3> _RMVZOEKLOG() Func _RMVZOEKLOG() $sFileZoekLog = @HomeDrive & "\zoek_results.log" If FileDelete($sFileZoekLog) Then ConsoleWrite("File deleted successfully." & @CRLF) Else ConsoleWrite("Error while deleting the file." & @CRLF) EndIf EndFunc ;==>_RMVZOEKLOG Doesn't tell you while it fails. You need to error check if the file exists first: #RequireAdmin #include <WindowsConstants.au3> #include <FileConstants.au3> _RMVZOEKLOG() Func _RMVZOEKLOG() $sFileZoekLog = @HomeDrive & "\zoek_results.log" If Not FileExists($sFileZoekLog) Then Return Msgbox(0,'',"File Does not exist! (So I don't need to delete it!)" & @CRLF) If FileDelete($sFileZoekLog) Then Msgbox(0,'',"File deleted successfully." & @CRLF) Else Msgbox(0,'',"Error while deleting the file." & @CRLF) EndIf EndFunc ;==>_RMVZOEKLOG Edited September 20, 2018 by kaisies Link to comment Share on other sites More sharing options...
Simpel Posted September 20, 2018 Share Posted September 20, 2018 Hi. The ASCII-ArrayDisplay returned to letters says „C:\zoek_results.log.txt“. Is it true? Maybe .txt is hidden by windows because it’s a known extension? Simpel FrancescoDiMuro, Danp2 and Nunos 2 1 SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Nunos Posted September 21, 2018 Author Share Posted September 21, 2018 So it looks like the file was named wrong and upon using show extensions for known file types it is named improperly. Thanks everyone for the help. 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