NicePerson Posted July 14, 2010 Share Posted July 14, 2010 (edited) I am trying to write all files name in a text file but i don't know what is error in my script. It writes only one file name but, msgbox shows all file names. Can someone help me plzzz. Here is 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 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $txt = FileOpen("Files.txt", 10) FileWrite($txt, "Files name " & $file) MsgBox(4096, "", "Files name " & $file) WEnd ; Close the search handle FileClose($search) Edited July 14, 2010 by RMR Link to comment Share on other sites More sharing options...
ajag Posted July 14, 2010 Share Posted July 14, 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! While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileWrite($txt, "Files name " & $file) MsgBox(4096, "", "Files name " & $file) WEnd ; Close the search handle FileClose($search) 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...
JohnOne Posted July 14, 2010 Share Posted July 14, 2010 (edited) expandcollapse popup$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) While 1 $file = FileFindNextFile($search) If @error Then ExitLoop ;$txt = FileOpen("Files.txt", 10) FileWrite($txt, "Files name " & $file & @CRLF) ;MsgBox(4096, "", "Files name " & $file) WEnd ; Close the search handle FileClose($txt) FileClose($search) Edited July 14, 2010 by JohnOne 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...
Moderators Melba23 Posted July 14, 2010 Moderators Share Posted July 14, 2010 RMR,Why make life difficult when AutoIt can do it for you in one line? #include <File.au3> _FileWriteFromArray(@ScriptDir & "\List.txt", _FileListToArray($@ScriptDir, "*.*", 1), 1)Just change the paths to your own versions. 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...
ajag Posted July 14, 2010 Share Posted July 14, 2010 RMR, Why make life difficult when AutoIt can do it for you in one line? #include <File.au3> _FileWriteFromArray(@ScriptDir & "\List.txt", _FileListToArray($@ScriptDir, "*.*", 1), 1) Just change the paths to your own versions. M23 maybe bc of the missing "No files.."-Messagebox ;-) 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...
Moderators Melba23 Posted July 14, 2010 Moderators Share Posted July 14, 2010 ajag,It was meant as a joke! Although it is still simpler with the MsgBox in:#include <File.au3> $aArray = _FileListToArray(@ScriptDir, "*.*", 0) If @error Then MsgBox(0, "Error", "No files/directories matched the search pattern") Else _FileWriteFromArray(@ScriptDir & "\List.txt", $aArray, 1) EndIf[joke]And still easier than playing around with FileFindFirst/NextFile. [/joke]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...
ajag Posted July 14, 2010 Share Posted July 14, 2010 [joke] And still easier than playing around with FileFindFirst/NextFile. [/joke] M23 Yep, and it's true - not a joke! 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...
NicePerson Posted July 14, 2010 Author Share Posted July 14, 2010 RMR, Why make life difficult when AutoIt can do it for you in one line? #include <File.au3> _FileWriteFromArray(@ScriptDir & "\List.txt", _FileListToArray($@ScriptDir, "*.*", 1), 1) Just change the paths to your own versions. M23 Melba23 Thanks a lot. Link to comment Share on other sites More sharing options...
GEOSoft Posted July 14, 2010 Share Posted July 14, 2010 [joke] And still easier than playing around with FileFindFirst/NextFile. [/joke] M23 If you trust those damn UDFs. I've lost all faith in the whole bunch. 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 14, 2010 Author Share Posted July 14, 2010 (edited) Hi guys whats up? I wanna ask something, lets go on... I got the file as list but i want to convert that list in one line and after every file name there should be a semicolon ; For example i got this list: File.txt File.exe File.jpg Now i want to convert this as File.txt;File.exe;File.jpg How can i do this? Edited July 14, 2010 by RMR Link to comment Share on other sites More sharing options...
Developers Jos Posted July 14, 2010 Developers Share Posted July 14, 2010 (edited) How can i do this?What about you try something yourself before posting?Jos Edited July 14, 2010 by 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...
omikron48 Posted July 14, 2010 Share Posted July 14, 2010 You're gonna have to write your own code to get that particular output. Either that, or you use the current code, then recreate the output text file into the format you want by coding a format converter. Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 Plz don't mind for my questions again and again. My question is i want to replace the last semicolon ";" with nothing and i also tried it meself but my script replaces all the semicolons with text. I want to replace only last one... Please don't mind and help me I got this: 1.txt;2.exe;3.jpg; But I Want this: 1.txt;2.exe;3.jpg Here is my try: $text = StringReplace("1.txt;2.exe;3.jpg;", ";", ".::Replaced text::.") $numreplacements = @extended MsgBox(0, "New string is", $text) MsgBox(0, "The number of replacements done was", $numreplacements) Thanks! Link to comment Share on other sites More sharing options...
omikron48 Posted July 15, 2010 Share Posted July 15, 2010 Read the help file better. $text = StringReplace("1.txt;2.exe;3.jpg;", ";", "", -1) Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 Thanks Link to comment Share on other sites More sharing options...
GEOSoft Posted July 15, 2010 Share Posted July 15, 2010 also $text = StringTrimRight($text, 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 $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 Link to comment Share on other sites More sharing options...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 Can someone help me plzzz... Thanks, RMR Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 15, 2010 Moderators Share Posted July 15, 2010 RMR, You have been here long enough to know that you should not bump your own posts within 24 hrs. Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. 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...
NicePerson Posted July 15, 2010 Author Share Posted July 15, 2010 OK Melba23 i will never do it again. Btw why people's accounts get blocked here? 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