Sign in to follow this  
Followers 0
Chetwood

Problems writing array to text file

7 posts in this topic

Silly me, I thought a one-dimensional array would be piece of cake but apparently I just don't get it! I want to write the folders one has selected from input boxes into a text file, so here is my array:

$num_discs = InputBox("", "How many folders?", "", "")

Global $discs[$num_discs]

For $i = 0 to $num_discs - 1
    $discs[$i] = FileSelectFolder("Select folder", "", 4, "")
Next

_ArrayDisplay displays the array as expected but I cannot write it to "folders.txt" which would look like this:

folder1

folder2

folder3

TIA!


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites



Thanks, are this functions mentioned somewhere in the help file? I've used "_FileWriteFromArray("array.txt",$discs)" for my example above, in that case the file is written but the first line is emtpy and folder1 starts in line 2. Also, I'm not too sure about the syntax when adding additional info to each line like

folder 1 has disc1

folder 2 ; some comment

folder 3\file.lst


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites

Yes, FileWriteFromArray() is a standard UDF included with the AutoIt installation and is listed in the help file. Would advise checking options within the help file on FileWriteFromArray() and if you still have your issues, then post what concerns you have.

:)

Share this post


Link to post
Share on other sites

Well, now that I started the AutoIt3Help.exe instead of AutoIt3.chm a search for FileWriteFromArray() turned up results. However, I'm still not sure whether this function does what I want. In my example I have 3 folders written to an array (index 0 to 2) and I want each entry to be written to a seperate text file and add my own text to it, file1.txt looks like this

d:\folder1\video_ts.ifo

d:\folder1 comes from array index1

\video_ts.ifo is added by me


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites

Something like this?

$num_discs = InputBox("", "How many folders?", "", "")

Global $discs[$num_discs], $f[10]
For $i = 0 to $num_discs - 1
    $f=FileOpen("folder" & $i+1 & ".txt", 2)
    $discs[$i] = FileSelectFolder("Select folder", "", 4, "")
    FileWriteLine($f, $discs[$i] & " your additional info")
    FileClose($f)
Next

I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks, it does what I want. But as you've guessed, I'm not getting the code. Global $f[10] seems to define another array but why one with 10 elements? I want to write as many files as there a discs so why not Global $f[$num_discs]? I also need to check whether each index item ends with a \ and if so the backslash has to be deleted.

Edited by Chetwood

MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

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