Sign in to follow this  
Followers 0
Redbeard

_FileWriteToLine Deleting ALL Lines

12 posts in this topic

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

Share this post


Link to post
Share on other sites



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]

Share this post


Link to post
Share on other sites

1st error noted by me

$TempFilePath = @ScriptDir & "\TempFile"

Maybe..

$TempFilePath = @ScriptDir & "\TempFile.txt"

???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

What is the return value?

The return value is 1

1st error noted by me

$TempFilePath = @ScriptDir & "\TempFile"

Maybe..

$TempFilePath = @ScriptDir & "\TempFile.txt"

???

8)

I've tried that, too but no luck.

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Manjish

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

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.

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.

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

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.

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Thanks 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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0