dogisay Posted March 16, 2021 Share Posted March 16, 2021 Respected Autoit Forum Members, If this is a problem my problem is basic. $path=@AppDataDir & "\etc\Isproblem.txt" FileOpen($path) ;FileClose($path) doesn't matter if it exists or not ;some code here FileDelete($path) ;some code here _FileCreate($path) ; It must be created in exactly the same path and with the same name. #cs -------------------------- Result: file cannot be created. #ce -------------------------- if you somehow force to create the file, this time, a file access problem occurs and cannot be overwritten. Although I can't understand why it is caused, I can overcome it in 3 ways 1- Don't use FileOpen 2- Restart the script 3- Create the file with another name or path and move it to its old location. Because of this problem, I had to remove "FileOpen" in all my code. But I still do not mind. Now I use this to clean files instead of.. FileOpen($path,2) FileClose($path) this one: _FileCreate($path) I apologize for keeping you busy, this was my unnecessary problem. Thanks. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 16, 2021 Share Posted March 16, 2021 Hi @dogisay, and to the AutoIt forum. Could you please post a runnable script, so we can try to assist you? 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...
Danp2 Posted March 16, 2021 Share Posted March 16, 2021 You can't delete a file that is currently open, and you aren't closing it correctly. Try this -- $path=@AppDataDir & "\etc\Isproblem.txt" $hFile = FileOpen($path) FileClose($hFile) ;some code here FileDelete($path) ;some code here _FileCreate($path) P.S. Welcome to the forum! dogisay 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
dogisay Posted March 16, 2021 Author Share Posted March 16, 2021 Thank you for your very quick replies. Dear Danp2, The problem still persists. As I said, independent of the file not closing. Dear FrancescoDiMuro, It is an honor to be among you. Of course I will want some time. Link to comment Share on other sites More sharing options...
Nine Posted March 16, 2021 Share Posted March 16, 2021 I would very strongly suggest that you put error handling after each statement, so you can know if there is something not working as expected.... dogisay 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Danp2 Posted March 16, 2021 Share Posted March 16, 2021 Not sure what problem you are referring to. Here's a modified version and my console output -- #include <File.au3> $path=@AppDataDir & "\etc\Isproblem.txt" ConsoleWrite($path & @CRLF) $hFile = FileOpen($path) ConsoleWrite("open=" & @error & @CRLF) FileClose($hFile) ConsoleWrite("close=" & @error & @CRLF) ;some code here FileDelete($path) ConsoleWrite("delete=" & @error & @CRLF) ;some code here _FileCreate($path) ConsoleWrite("FileCreate=" & @error & @CRLF) >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\danpollak\Dropbox\webdriver\test3.au3" /UserParams +>10:46:07 Starting AutoIt3Wrapper (19.1127.1402.26) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\danpollak\Dropbox\webdriver\test3.au3 +>10:46:08 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\danpollak\Dropbox\webdriver\test3.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. C:\Users\danpollak\AppData\Roaming\etc\Isproblem.txt open=0 close=0 delete=0 FileCreate=0 +>10:46:08 AutoIt3.exe ended.rc:0 +>10:46:08 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.256 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
dogisay Posted March 16, 2021 Author Share Posted March 16, 2021 48 minutes ago, Danp2 said: You can't delete a file that is currently open, and you aren't closing it correctly. Try this -- $path=@AppDataDir & "\etc\Isproblem.txt" $hFile = FileOpen($path) FileClose($hFile) ;some code here FileDelete($path) ;some code here _FileCreate($path) P.S. Welcome to the forum! Oh sorry, I noticed that all this time I am not using "FileClose" as it should be. Yes this solves the problem. Thanks for all your advice and help. Link to comment Share on other sites More sharing options...
Nine Posted March 16, 2021 Share Posted March 16, 2021 @dogisay. Not all function returns an @error. Some (ex. fileopen) returns -1 for an error. Make sure you write both return value AND @error “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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