Jump to content

[SOLVED] _FileListToArray, need an explanation


Recommended Posts

Hi guys,

I know that normally when should ask for help you need to post a code. But this time i don't know how to start. I search in the guide and in the forum but i can't find a good example for what i'm want to do.

What i want to do:

1) Make a GUI for select a folder ( i know how to do )

2) Copy the complete path of all file in that folder ( ? ) and write them on a ini file

3) Make every line on .ini a variable ( ? ) for a cmd command ( i know how to do )

_FileListToArray i think is the right command, but i can't find a good example for starting scripting

Thanks for support,

John

Edited by johnmcloud
Link to comment
Share on other sites

  • Moderators

johnmcloud,

_FileListToArray is indeed the function you need. Why do you say the example in the Help file not "a good example"? It seems to cover the requirements to me - call the function with a path, and then optionally a mask to determine what matches you get and what you want returned (files/folders/both). All you need to do is to assign the return value to an array. ;)

And why do you need to write the array to an ini file? Are you going to use these filenames later or straightaway? If you want to use them immediately you can just loop through the array with a For...Next loop. :D

Finally what "cmd command" are you going to use on them? Is there not an AutoIt equivalent? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for answer.

For the cmd command, there is no equivalent because is a software without gui, need to use cmd like:

pathsoftware pathfile /option

The software can select only 1 file at time, so i want to write something with autoit for select the folder, write the path of all the file, start the cmd/software a process one line at time

For the "good example", i can't find someone do the same thing i want to do with _FileListToArray, like save the path of all file in a .ini or .txt :)

Link to comment
Share on other sites

  • Moderators

johnmcloud,

Once you have the filenames in the array after using _FileListToArray, you need to use a loop to go through them and write them to a file. :)

Look at For...To...Step...Next to see how to set up a loop - the "loop variable" is used to get the array element. Then when you have the filename, you can use FileWriteLine to add it to your file. Do read the Help file carefully - you will be doing several of the operations so it is much faster to open the file first with FileOpen. But then you must use the returned file handle in FileWriteLine as shown in the example. Later on you will be able to use FileReadLine to pull the names from the file one by one to pass to your software. :D

Give it a go yourself - you know where we are if you run into difficulties. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks M23, for now i have made this:

#Include <File.au3>
#Include <Array.au3>

$File = @Workingdir & "Test.txt"
$Path = @ScriptDir
$Folders= _FileListToArray($Path, '*', 1)
$pre = "SoftwarePath"
$post = "/option"

For $i = 0 to UBound($Folders) -1
    $Folders[$i] = $pre & " " & '"' & $Path & "" & $Folders[$i] & '"' & " " & $post
Next

_FileWriteFromArray($File, $Folders)
IniWrite("???")

The result is:

SoftwarePath "C:Documents and SettingsWindows XpDesktop3" /option
SoftwarePath "C:Documents and SettingsWindows XpDesktopautoit-v3-setup.exe" /option
SoftwarePath "C:Documents and SettingsWindows XpDesktoptest.au3" /option
SoftwarePath "C:Documents and SettingsWindows XpDesktopTest.txt" /option

I don't have a file named "3" :) How to remove it?

And how to iniwrite at first line without delete the path of the file?

Edited by johnmcloud
Link to comment
Share on other sites

_FileListToArray writes the number of found files and folders to the [0] element of the array, that's what the 3 is. You need to use For $i = 1 to Ubound($folders) - 1 instead of starting at 0.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

johnmcloud,

What does that Help file (notice how I keep mentioning it ;)) say about the array that you get returned from _FileListToArray? :)

The array returned is one-dimensional and is made up as follows:

$array[0] = Number of FilesFolders returned <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$array[1] = 1st FileFolder

$array[2] = 2nd FileFolder

$array[3] = 3rd FileFolder

$array[n] = nth FileFolder

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks to both, now i have:

6
SoftwarePath -c "C:Documents and SettingsWindows XpDesktopautoit-v3-setup.exe"<test.txt
SoftwarePath -c "C:Documents and SettingsWindows XpDesktoptest.au3"<test.txt
SoftwarePath -c "C:Documents and SettingsWindows XpDesktopTest.ini"<test.txt

I have sobstitute the line like this:

@echo off
SoftwarePath -c "C:Documents and SettingsWindows XpDesktopautoit-v3-setup.exe"<test.txt
SoftwarePath -c "C:Documents and SettingsWindows XpDesktoptest.au3"<test.txt
SoftwarePath -c "C:Documents and SettingsWindows XpDesktopTest.ini"<test.txt

#Include <File.au3>
#Include <Array.au3>
#include <file.au3>

$File = @Workingdir & "Test.ini"
$Path = @ScriptDir
$Folders= _FileListToArray($Path, '*', 1)
$Bat1 = "@echo off"
$pre = "SoftwarePath"
$command = "-c"
$post = "<test.txt"

For $i = 1 to UBound($Folders) -1
    $Folders[$i] = $pre & " " & $command & " " & '"' & $Path & "" & $Folders[$i] & '"' & $post
Next
_FileWriteFromArray($File, $Folders)
_FileWriteToLine($File, 1, $Bat1, 1)

How to make the second line of the ini return 3 line down?

I need more space for the .bat

Thanks for support and for time

EDIT: what a fool!

_FileWriteToLine($File, 2, $Bat1, 0)
Edited by johnmcloud
Link to comment
Share on other sites

  • Moderators

johnmcloud,

Here is a slightly more elegant way of getting your @echo off into the file: ;)

#Include <File.au3>
#Include <Array.au3>

$File = @Workingdir & "Test.ini"
$Path = @ScriptDir
$Folders= _FileListToArray($Path, '*', 1)
; Replace the count with your required text <<<<<<<<<<<<<<
$Folders[0] = "@echo off"
$pre = "SoftwarePath"
$command = "-c"
$post = "<test.txt"

For $i = 1 to UBound($Folders) - 1
    $Folders[$i] = $pre & " " & $command & " " & '"' & $Path & "" & $Folders[$i] & '"' & $post
Next
_FileWriteFromArray($File, $Folders)
; Now there is no need to use _FileWriteLine <<<<<<<<<<<<<<

How to make the second line of the ini return 3 line down?

I am afraid I do not understand this - can you explain further or show us what the file should look like? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#Include <File.au3>
#Include <Array.au3>
#include <file.au3>
 
$File = @Workingdir & "Test.bat"
$Path = @ScriptDir
$Folders= _FileListToArray($Path, '*', 1)
 
$Pre = "SoftwarePath"
$Command = "-c"
$Post = "<test.txt"
 
$Bat1 = "@echo off"
$Bat2 = "echo TEST>test.txt"
$Bat3 = "echo TEST>>test.txt"
 
For $i = 1 to UBound($Folders) -1
    $Folders[$i] = $pre & " " & $command & " " & '"' & $Path & "" & $Folders[$i] & '"' & $post
Next
_FileWriteFromArray($File, $Folders)
 
_FileWriteToLine($File, 1, $Bat1, 1)
_FileWriteToLine($File, 2, $Bat2, 0)
_FileWriteToLine($File, 3, $Bat3, 0)
_FileWriteToLine($File, 4, " ", 0)

Result

@echo off
echo TEST>test.txt
echo TEST>>test.txt
 
SoftwarePath -c "C:Documents and SettingsWindows XpDesktopautoit-v3-setup.exe"<test.txt
SoftwarePath -c "C:Documents and SettingsWindows XpDesktoptest.au3"<test.txt
SoftwarePath -c "C:Documents and SettingsWindows XpDesktopTest.ini"<test.txt

If someone have better idea to do this, simply ask, i'm here to learn :)

Link to comment
Share on other sites

  • Moderators

johnmcloud,

Just do as I did above, but add some @CRLF into the [0] element:

#Include <File.au3>
#Include <Array.au3>

$File = @Workingdir & "Test.bat"
$Path = @ScriptDir
$Folders= _FileListToArray($Path, '*', 1)

; Replace the count with your starter lines separated by @CRLF
$Folders[0] = "@echo off" & @CRLF & "echo TEST>test.txt" & @CRLF & "echo TEST>>test.txt" & @CRLF

$Pre = "SoftwarePath"
$Command = "-c"
$Post = "<test.txt"

For $i = 1 to UBound($Folders) -1
    $Folders[$i] = $pre & " " & $command & " " & '"' & $Path & "" & $Folders[$i] & '"' & $post
Next
_FileWriteFromArray($File, $Folders)

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

×
×
  • Create New...