Redbeard Posted January 16, 2009 Posted January 16, 2009 Hello, I'm obviously not understanding something about _FileWriteToLine. I'm writing a script that will take a list of video files from the command line, separate them with line feeds (@LF), and write them to a temp file for later batch conversion. When doing the conversion my plan was to read a line(filename) from the temp file to a variable, delete that line and proceed with the video conversion. I can write the temp file fine, read the first line as expected, but when I try to use _FileWriteToLine to delete that first line it deletes all lines making the file blank. I'm sure there is some simple reason it's not working but I can't figure it out. Any help would be greatly appreciated. Here is an example: #include <File.au3> ;imaginary command line $CommandLine = """C:\temp\file1.avi""" & " " & """C:\temp\file2.avi""" & " " & """C:\temp\file3.avi""" & " " & """C:\temp\file4.avi""" & " " & """C:\temp\file5.avi""" $TempFilePath = @ScriptDir & "\TempFile" $FileList = $CommandLine ;separate command line into individual files $FileList = StringReplace($FileList,"""" & " " & """","""" & @LF & """") ;write file names to temp file $TempFile = FileOpen($TempFilePath,2) FileWrite($TempFile,$FileList) FileClose($TempFile) MsgBox(0,"Wait","Ensure file list was created and correctly written") ;later in script temp file would be reopened and read line by line, deleting each line after reading it. $TempFile = FileOpen($TempFilePath,0) $CurrentFile = FileReadLine($TempFile) FileClose($TempFile) _FileWriteToLine($TempFilePath,1,"",1) Exit
bo8ster Posted January 16, 2009 Posted January 16, 2009 What is the return value? 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]
Valuater Posted January 16, 2009 Posted January 16, 2009 1st error noted by me $TempFilePath = @ScriptDir & "\TempFile" Maybe.. $TempFilePath = @ScriptDir & "\TempFile.txt" ??? 8)
taz742 Posted January 16, 2009 Posted January 16, 2009 @Valuter: you're right using a filefullpath without extention for a file is not recommanded.@Redbeard: Replace @LF by @CRLF into your script and it will run as expected.
Redbeard Posted January 16, 2009 Author Posted January 16, 2009 What is the return value?The return value is 11st error noted by me$TempFilePath = @ScriptDir & "\TempFile"Maybe..$TempFilePath = @ScriptDir & "\TempFile.txt"???8)I've tried that, too but no luck.
Redbeard Posted January 16, 2009 Author Posted January 16, 2009 @Valuter: you're right using a filefullpath without extention for a file is not recommanded.@Redbeard: Replace @LF by @CRLF into your script and it will run as expected.The temp file is created only for this temp usage so I'm not worried about the lack of an extension, I've used it this was many times before. But, the @CRLF worked even though I would have sworn I had tried that. Thank you all for your help.
Manjish Posted January 16, 2009 Posted January 16, 2009 (edited) why do u want to erase the line after reading it? Use a for loop to read the line till it gets a blank line. increment the line no. every time. for $i=1 to 200 ;any number. $var= filereadline($file,$i); read line no. 1 to the last line if $var="" then exitloop; exit if blank line next Simple n sweet. I use this all the time. works fine. Edited January 16, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Redbeard Posted January 16, 2009 Author Posted January 16, 2009 why do u want to erase the line after reading it?Use a for loop to read the line till it gets a blank line. increment the line no. every time.for $i=1 to 200 ;any number.$var= filereadline($file,$i); read line no. 1 to the last lineif $var="" then exitloop; exit if blank linenextSimple n sweet. I use this all the time. works fine.Well, like I said it's just a temp file. I use it to batch convert video files, and since this is fairly resource intensive I don't want more than one version of the converter to run at a time. So, by using a temp file and deleting each line after use I can continue to add files, via command line, to the temp file while the converter is running. I suppose there isn't any extreme benefit to deleting the line but since it always reads the first line there is some minimal amount of time saved by not searching the file for the "next" line. Thanks for the input, though.
Developers Jos Posted January 16, 2009 Developers Posted January 16, 2009 I would think that this code overrides all record as you are opening it with 2 = Write mode (erase previous contents) $CommandLine = """C:\temp\file1.avi""" & " " & """C:\temp\file2.avi""" & " " & """C:\temp\file3.avi""" & " " & """C:\temp\file4.avi""" & " " & """C:\temp\file5.avi""" $TempFilePath = @ScriptDir & "\TempFile" $FileList = $CommandLine ;separate command line into individual files $FileList = StringReplace($FileList, """" & " " & """", """" & @LF & """") ;write file names to temp file $TempFile = FileOpen($TempFilePath, 2) FileWrite($TempFile, $FileList) FileClose($TempFile) Don't you want to use 1 = Write mode (append to end of 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.
Redbeard Posted January 16, 2009 Author Posted January 16, 2009 I would think that this code overrides all record as you are opening it with 2 = Write mode (erase previous contents) $CommandLine = """C:\temp\file1.avi""" & " " & """C:\temp\file2.avi""" & " " & """C:\temp\file3.avi""" & " " & """C:\temp\file4.avi""" & " " & """C:\temp\file5.avi""" $TempFilePath = @ScriptDir & "\TempFile" $FileList = $CommandLine ;separate command line into individual files $FileList = StringReplace($FileList, """" & " " & """", """" & @LF & """") ;write file names to temp file $TempFile = FileOpen($TempFilePath, 2) FileWrite($TempFile, $FileList) FileClose($TempFile) Don't you want to use 1 = Write mode (append to end of file) ? JosThe code listed is for the first instance of the script. If I run the script again, via command line, to add more files to the batch then it uses the 1 Write Mode, adds the new files to the list and exits.
Developers Jos Posted January 16, 2009 Developers Posted January 16, 2009 The code listed is for the first instance of the script. If I run the script again, via command line, to add more files to the batch then it uses the 1 Write Mode, adds the new files to the list and exits.Not sure I understand and I can only judge what I am seeing The posted script will zap any records that were in the file... maybe post the scriptlet that you have the problem with ?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.
Redbeard Posted January 16, 2009 Author Posted January 16, 2009 Not sure I understand and I can only judge what I am seeing The posted script will zap any records that were in the file... maybe post the scriptlet that you have the problem with ?JosThanks for your help but we've got it figured out. As taz742 pointed out all I had to do was switch my @LF for @CRLF and it worked fine. Although, like I said, I could have sworn I tried that. Thanks again for the help.
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