Rhyono Posted December 9, 2012 Share Posted December 9, 2012 This looks like an extremely straightforward function...yet it isn't working for me. I have a text file with 20 characters, no weird characters. It is only one line, and it is in the same folder as the script. So I tried to open it using $file = FileOpen("text.txt",0) and it didn't work. The file was made in notepad on W7. Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 (edited) Rhyono, Have you looked at the help file for "fileopen"? $file contains a handle to your file which is now open in read mode, assuming that the file exists. You can now read the file with fileread or filereadline. Given the size of the file it would be just as easy fot you to read it like this $file_contents = fileread(@scriptdir & "text.txt") kylomas edit: spelling Edited December 9, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 This contains a bad example then, since it doesn't give any indication that you need to specify the directory and implies otherwise. Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Rhyono, There is nothing in the doc that intimates file search order. The example could be improved, however, this is the first time that I can recall anyone making the assumption that Autoit somehow finds the file. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Xandy Posted December 9, 2012 Share Posted December 9, 2012 Sure we can read the example anyway we like. 'Filename' is like saying 'filepath' and a filepath is either relative or a full path. I have found that it is good practice for me to always tell the program where to look as dialogs will often change a working directory, and that destroys the precision I require for my programs to locate files. I'm glad there's a help at all. Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 By "improved" you mean it could be changed to an example that would work in at least one instance? If you saw an example which did not specify a directory, and you assumed it was written by someone who knew what they were doing, I believe you'd be more inclined to think "it must use the current directory" over "this guy is lazy." @Xandy If the example had used a placeholder like "filename": yeah, I would've assumed path too. However, it specifically used just a filename. Xandy 1 Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Rhyono, I will agree that the example scripts should at least run, as coded. I'll put something in the thread that handles these kinds of problems. kylomas Xandy 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
ripdad Posted December 9, 2012 Share Posted December 9, 2012 Actually, that example should read closer to this... Local $sPath = @ScriptDir Local $sFile = "test.txt" Local $hFile = FileOpen($sPath & '' & $sFile, 0) ; Check if file opened for reading OK If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileClose($hFile) This way... it breaks it down properly to the reader: 1) The Path that the file resides in. 2) The File Name with Extension. 3) The Handle of the File, once opened. This will kill the idea that the reader only needs a file name to work. Just my opinion. Xandy 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Rhyono, ripdad's example looks good to me, what does it look like from a new user's perspective? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Developers Jos Posted December 9, 2012 Developers Share Posted December 9, 2012 This contains a bad example then, since it doesn't give any indication that you need to specify the directory and implies otherwise.Guys, come on, where are the days we also expect people to think and understand what is happening when programming.Whatever we do in the examples, there always will be something that could be "improved".In this case my humble opinion is that the examples are fine and have been for the past 10 years.Jos Xandy and czardas 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...
JohnOne Posted December 9, 2012 Share Posted December 9, 2012 You cannot underestimate the stupidity of people though. I made a snippet for a file function, and felt the need to actually create the file to be worked on in its example by using this rule. But I do agree, that if someone cannot figure that out, they probably have no business entering into the world of scripting. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 9, 2012 Developers Share Posted December 9, 2012 I was not trying to imply that the OP is stupid. merely that this should be considered a learning moment and not an issue with the helpfile. 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...
JohnOne Posted December 9, 2012 Share Posted December 9, 2012 Nor was I for the record. But, meh! if the cap fits... AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ripdad Posted December 9, 2012 Share Posted December 9, 2012 Everyone starts from somewhere. We all had to do this in the beginning. A new programmer will have to understand what a path is, before they learn anything else. I can't remember, but I'm sure I had some difficulty understanding it at first. I wasn't born with that knowledge. It takes some time to grasp basic coding practices. So, for someone reading the help file for the very first time (about files), it helps to have a proper structure in order to better understand what they are reading. Anyways, just my 2 cents (which used to buy some bubble gum). trancexx and Xandy 2 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 Just for the record: I am quite capable in C++, Java, Python, Perl, BASIC, and Visual Basic. I'm extremely capable in PHP and Javascript. In those languages, when I look at the help files and I see example code and it doesn't work for me, I assume I did something wrong, rather than the example being wrong itself. I chose this language due to a few shortcomings of Java's Robot Class and transcribed a bot from a language I have had a lot of experience with to a language I've had no experience with in a matter of a couple hours. I disagree with the implication, that several of you have made, that I am inept. 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