ajag Posted July 15, 2010 Share Posted July 15, 2010 $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $txt = FileOpen("Files.txt", 10) ;<<<<<<<< this must not be within the While-Loop! $txt2 = FileOpen("Files2.txt", 10) ;<<<<<<<< this must not be within the While-Loop! While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileWrite($txt, $file & ";") $read = FileRead($txt) $text = StringTrimRight($read, 1) FileWrite($txt2, $text) WEnd ; Close the search handle FileClose($search) Not working Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings. A-Jay Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
omikron48 Posted July 15, 2010 Share Posted July 15, 2010 (edited) What in particular is not working? Edited July 15, 2010 by omikron48 Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 This is written for getting all files name in a text file and each name should be seperated with semicolon. when i run this it works fine but i don't want semicolon at the last of text file. So , can you help me please? i tried to trim last word but that does not work... $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $txt = FileOpen("Files.txt", 10) ;<<<<<<<< this must not be within the While-Loop! $txt2 = FileOpen("Files2.txt", 10) ;<<<<<<<< this must not be within the While-Loop! While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileWrite($txt, $file & ";") $read = FileRead($txt) $text = StringTrimRight($read, 1) FileWrite($txt2, $text) WEnd Link to comment Share on other sites More sharing options...
omikron48 Posted July 15, 2010 Share Posted July 15, 2010 You need to close the file handles for the written data to be saved. Also, why write everything to the file directly? Why not just process all the data using strings then just do one FileWrite when all the processing is over with? Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 why write everything to the file directly? Why not just process all the data using strings then just do one FileWrite when all the processing is over with?Can you give me an example? Link to comment Share on other sites More sharing options...
omikron48 Posted July 15, 2010 Share Posted July 15, 2010 Opt("MustDeclareVars", 1) Global $strings[5] = ["text1", "text2", "text3", "text4", "text5"] Global $output = "" For $i = 0 To 4 $output &= $strings[$i] & ";" Next $output = StringTrimRight($output, 1) FileWrite("sample.txt", $output) MsgBox(0x2000, "Sample", $output) Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 How to do this in my script? $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $txt = FileOpen("Files.txt", 10) ;<<<<<<<< this must not be within the While-Loop! $txt2 = FileOpen("Files2.txt", 10) ;<<<<<<<< this must not be within the While-Loop! While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileWrite($txt, $file & ";") $read = FileRead($txt) $text = StringTrimRight($read, 1) FileWrite($txt2, $text) WEnd Link to comment Share on other sites More sharing options...
omikron48 Posted July 15, 2010 Share Posted July 15, 2010 You can figure it out on your own. The example I gave is plenty enough to work on. Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 i can't figure it on mine i am a newbie. write this please... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 15, 2010 Moderators Share Posted July 15, 2010 RMR, why people's accounts get blocked here?Bumping your own posts too quickly, not making any effort yourself, and using phrases like "write this please..." are a good way to draw the attention and ire of the moderating team, as already shown in this post earlier in this very topic. And continuing in your present manner may well mean that you cease to get any help from the regular members, which I am sure you would not want either. I suggest that you try to make a greater effort to resolve your problems yourself. There is no shame in being a new coder - we all started there at some point - but you need to start trying some things yourself. I borrowed this from Mat's signature, but the sentiment is one I share fully: Hear and forget. See and remember. Do and understand. So, try a few things for yourself. have you read and understood the excellent tutorials that you find here and here? If not, please do so - they will help you enormously in understanding how AutoIt code is structured. We have many members here who have little or no understanding of the code they (with the help of many others) have produced. Remember the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers. But it is up to you to learn to how to throw your net. We are more than willing to help, but we need to see more effort on your part. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Developers Jos Posted July 15, 2010 Developers Share Posted July 15, 2010 i can't figure it on mine i am a newbie.write this please...Let me make it easy for you: You either start putting some effort in it yourself or you will be put on a "posting questions ban" for a while.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...
bo8ster Posted July 15, 2010 Share Posted July 15, 2010 Hear and forget. See and remember. Do and understand."Give a man a fish, you feed him for a day; give a man a net and you feed him forever".M23Nice, I like the first one. Here is oneTo teach is to learn twice.@RMR - it looks like you may be trying to bit off a bit to much. Look a Files (reading and writing) in the help file and play round with them then try to introduce more things slowly. This way you will understand what the code is doing and errors will be much more obvious. I also you look up ConsoleWrite as it can be used in your code to help understanding what is going on where - this print out vars. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
GEOSoft Posted July 15, 2010 Share Posted July 15, 2010 What are you trying to do with a FileRead() in that loop? Are you trying to contcatenate files or just create a file list? You don't use FileRead(0 in a list situation.Btw why people's accounts get blocked here?For breaking any forum rules but mainly for repeated offences of the followingPosting on topics that are not allowedArguing with moderatoreGeneral stupidity. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 I was just trying to get a all files name seperated by ; like this: text1;text2;text3;text4;text5 but i am getting this: text1;text2;text3;text4;text5; i tried my self then asked here but all of you started to began angry... Link to comment Share on other sites More sharing options...
GEOSoft Posted July 15, 2010 Share Posted July 15, 2010 Fileread does what it says it does, it READS a file so you don't need that and I already gave you the solution for the semi-colon as have others. $sStr = "text1;text2;text3;text4;text5;" $sStr = StringTrimRight($sStr, 1) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 (edited) GEOSoft, I followed your method but... $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $txt = FileOpen("Files.txt", 10) ;<<<<<<<< this must not be within the While-Loop! While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $sStr = $file & ";" $sStr = StringTrimRight($sStr, 1) FileWrite($txt, $sStr) WEnd ; Close the search handle FileClose($search) Files.txt should be contain: text1;text2;text3;text4;text5 But it contain: text1text2text3text4text5 I tried a lot now what is my mistake? Please don't mind!!1 Edited July 15, 2010 by RMR Link to comment Share on other sites More sharing options...
GEOSoft Posted July 15, 2010 Share Posted July 15, 2010 $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $sStr = "" While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $sStr &= $file & ";";; You are changing the value of $sStr everytime you do this. You want to just append the next file and the ; ;;$sStr = StringTrimRight($sStr, 1);; Only after the loop has completed ;;FileWrite($txt, $sStr);; We already told you about NOT putting this in a loop. FileWriteLine() would be different WEnd ; Close the search handle FileClose($search) If $sStr ;; here we check for a valid string ;; If we have a valid string then perform the next operation. $txt = FileOpen("Files.txt", 10) FileWrite($txt, StringTrimRight($sStr, 1)) FileClose($txt) ;; Close the handle to the open file EndIf Now a bit of checking in the help file and you would have had no difficulty what-so-ever seeing what we pointed out earlier. The help file is the best friend you have around here so you better learn to use it. Don't just read our replies and guess at how to implement the suggestions, check on the function usage. We don't write people code for them, instead we deal in generalities that will point them in the right direction and that direction will invariably lead to the help file. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
omikron48 Posted July 15, 2010 Share Posted July 15, 2010 Are you paying attention to what your code is actually doing step by step? It's easy to spot what you are doing wrong if you trace what your program is doing versus what you want it to do. 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