VladProgramatorul Posted July 7, 2017 Share Posted July 7, 2017 Hello ! Yesterday, I tested my script and that created a file well in my script directory but today i don't know what happened and this don't create at all. The problem is that even if i create a new script file this don't create any file. I've tried to run as administrator but it don't work and no error display. I want to tell you that the script can create the file anywhere in my computer but only in script directory not. The script is actually, a little big (1739 lines) so I can't paste here but I think is not the problem from the script since this don't let me from any other scripts to create. Any solutions ? Thank you ! Link to comment Share on other sites More sharing options...
Developers Jos Posted July 7, 2017 Developers Share Posted July 7, 2017 Show how you write to the file. Do you have the fully qualified path in it or just the filename? In case of the latter: what is the WorkDir when writing to the file? Jos 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...
VladProgramatorul Posted July 7, 2017 Author Share Posted July 7, 2017 Hi ! Thank you for your fast response ! The code look like that : FileOpen("File.txt", 1) FileWriteLine("File.txt", "Write something") FileClose("File.txt") ______________________________________ I also tried : FileOpen(@ScriptDir & "File.txt", 1) FileWriteLine(@ScriptDir & "File.txt", "Write something") FileClose(@ScriptDir & "File.txt") ______________________________________ I tried to change the mode that open the file but with no results.. The WorkDir is the same as ScriptDir. Link to comment Share on other sites More sharing options...
Developers Jos Posted July 7, 2017 Developers Share Posted July 7, 2017 Just now, VladProgramatorul said: FileOpen(@ScriptDir & "File.txt", 1) FileWriteLine(@ScriptDir & "File.txt", "Write something") FileClose(@ScriptDir & "File.txt") This is invalid coding as you need to use the FileHandle returned by FileOpen! On top of that you are missing a backslash before the filename. Something like this should be the correct way: $fh = FileOpen(@ScriptDir & "\File.txt", 1) FileWriteLine($fh, "Write something") FileClose($fh) The helpfile is your friend Jos Skysnake and VladProgramatorul 2 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...
VladProgramatorul Posted July 7, 2017 Author Share Posted July 7, 2017 Thank you so much ! I didn't think not even a second this could be the problem Link to comment Share on other sites More sharing options...
Fr33b0w Posted July 7, 2017 Share Posted July 7, 2017 Don't get me wrong because i want to learn this code also, it doesn't matter if at the end of the code you get FileClose(FileOpen(@ScriptDir & "\File.txt", 1)) File will be closed anyway because its the last executed command, right? Link to comment Share on other sites More sharing options...
Developers Jos Posted July 7, 2017 Developers Share Posted July 7, 2017 Not sure why you show the FileOpen() inside the FileClose(), but yes, at the end of the script execution all handles will be closed and memory freed. It will be an issue though when you do those 3 commands repeatedly in a loop leaving all those files instances open. Jos Fr33b0w 1 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...
Fr33b0w Posted July 8, 2017 Share Posted July 8, 2017 Thank You for your answer. You are very active and have a lot of patience to help novice people which is really nice to see apart from programming part. So... if you have $fh = FileOpen(@ScriptDir & "\File.txt", 1) then content of the $fh after that line is just path to file.txt: @ScriptDir & "\File.txt" not FileOpen(@ScriptDir & "\File.txt", 1) right? I have gaps like that because I didnt learn it the way it should be learned. just when I need something then I go and search, borrow and code. Thanks! Link to comment Share on other sites More sharing options...
Developers Jos Posted July 8, 2017 Developers Share Posted July 8, 2017 (edited) You must also open a file before any I/O operation can be performed on it. FileOpen allocates a buffer for I/O to the file and determines the mode of access to use with the buffer. The FileHandle is a reference to this allocated buffer/file. So in case in AutoIt3 you only have an FileRead() statement, then under the hood, AutoIt3 will do an FileOpen(), FileRead(), FIleCLose(). That is also why an FileOpen(), then looping through the records and ending with an FileCLose() is much faster then only using a FileRead(filename, Recordnumber) as that avoids maybe Open/Close actions. JOs Edited July 8, 2017 by Jos Fr33b0w 1 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...
Fr33b0w Posted July 8, 2017 Share Posted July 8, 2017 I am learning how to optimize my code. You are not only delivering knowledge but good karma on the forum which is sometimes more needed then anything else in life. Thank You very much for all of that. Skysnake 1 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