mmletzko Posted June 18, 2009 Share Posted June 18, 2009 Trying to replace commas with a space in a file filled with directly paths that include commas, but its just hanging. What am I missing? I'm outputting to csv and the commas are throwing the columns off so I want to replace them before output. $i=0 $dirlist=FileOpen("c:\temp\dirlist.txt",1) While 1 $dirline=FileReadLine($dirlist) If StringInStr($dirline,",") Then StringReplace($dirline,","," ") EndIf If @error=-1 Then ExitLoop WEnd Link to comment Share on other sites More sharing options...
Zedna Posted June 18, 2009 Share Posted June 18, 2009 (edited) $dirline = StringReplace($dirline,","," ") EDIT: $i=0 $dirlist=FileOpen("c:\temp\dirlist.txt",1) While 1 $dirline=FileReadLine($dirlist) If @error=-1 Then ExitLoop If StringInStr($dirline,",") Then $dirline = StringReplace($dirline,","," ") EndIf WEnd but you don't use modified $dirline Edited June 18, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 18, 2009 Moderators Share Posted June 18, 2009 (edited) You're not changing anything... Are you trying to write them back to the file? Are you trying to store the values in a variable? Local $s_no_comma = StringReplace(FileRead("c:\temp\dirlist.txt"), ",", " ") FileWrite("c:\temp\no_comma_dirlist.txt", $s_no_comma) Edit: BTW, the reason you probably hang is you need to check the @error "After" FileReadLine() in your code, but it still won't work because you don't save StringReplace() to a variable. Edited June 18, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
mmletzko Posted June 18, 2009 Author Share Posted June 18, 2009 Thanks for the replies guys, but its still not working. I modified the code to look like this: $dirlist=FileOpen("c:\temp\dirlist.txt",1) While 1 $dirline=FileReadLine($dirlist) If @error=-1 Then ExitLoop If StringInStr($dirline,",") Then Local $s_no_comma = StringReplace(FileRead($dirlist), ",", " ") FileWrite($dirlist,$s_no_comma) EndIF WEnd FileClose ($dirlist) Link to comment Share on other sites More sharing options...
mmletzko Posted June 18, 2009 Author Share Posted June 18, 2009 I'll add all the relative code: Seems when I use the "1" option for the FileOpen it just loops. If I change it to a 0 (Read), the script finishes, but doesn't replace the strings, which would make sense since the file would only be open for reading. #Include <Process.au3> _RunDos("dir c:\temp\*. /s /b > c:\temp\dirlist.txt") $dirlist=FileOpen("c:\temp\dirlist.txt",1) While 1 $dirline=FileReadLine($dirlist) If @error=-1 Then ExitLoop If StringInStr($dirline,",") Then Local $s_no_comma = StringReplace(FileRead($dirlist), ",", " ") FileWrite($dirlist,$s_no_comma) EndIF WEnd FileClose ($dirlist) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 18, 2009 Moderators Share Posted June 18, 2009 I'll add all the relative code: Seems when I use the "1" option for the FileOpen it just loops. If I change it to a 0 (Read), the script finishes, but doesn't replace the strings, which would make sense since the file would only be open for reading. #Include <Process.au3> _RunDos("dir c:\temp\*. /s /b > c:\temp\dirlist.txt") $dirlist=FileOpen("c:\temp\dirlist.txt",1) While 1 $dirline=FileReadLine($dirlist) If @error=-1 Then ExitLoop If StringInStr($dirline,",") Then Local $s_no_comma = StringReplace(FileRead($dirlist), ",", " ") FileWrite($dirlist,$s_no_comma) EndIF WEnd FileClose ($dirlist)Try running just this: RunWait(@Comspec & " /c dir c:\temp\* /s /b > c:\temp\dirlist.txt", "", @SW_HIDE) Local $s_read_file = FileRead("C:\temp\dirlist.txt") FileClose(FileOpen("C:\temp\dirlist.txt", 2)) FileWrite("C:\temp\dirlist.txt", StringReplace($s_read_file, ",", " ")) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
mmletzko Posted June 18, 2009 Author Share Posted June 18, 2009 Try running just this: RunWait(@Comspec & " /c dir c:\temp\* /s /b > c:\temp\dirlist.txt", "", @SW_HIDE) Local $s_read_file = FileRead("C:\temp\dirlist.txt") FileClose(FileOpen("C:\temp\dirlist.txt", 2)) FileWrite("C:\temp\dirlist.txt", StringReplace($s_read_file, ",", " ")) That worked Smoke. You know, I actually originally had the "RunWait" with the @SW_HIDE option but it wasn't running when I used the @SW_HIDE option...ran fine without it. Strange. I'll make the necessary adjustments and incorporate into my script. Thanks again! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 18, 2009 Moderators Share Posted June 18, 2009 That worked Smoke.You know, I actually originally had the "RunWait" with the @SW_HIDE option but it wasn't running when I used the @SW_HIDE option...ran fine without it. Strange.I'll make the necessary adjustments and incorporate into my script.Thanks again!Your command was wrong... you had "*.", should have been "*" ... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
mmletzko Posted June 18, 2009 Author Share Posted June 18, 2009 Your command was wrong... you had "*.", should have been "*" ...Actually I only wanted folders, not files. Its working great now. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 18, 2009 Moderators Share Posted June 18, 2009 Actually I only wanted folders, not files. Its working great now. using the switch/dCould accomplish that for you. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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