Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] _FileListToArray, need an explanation

13 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thanks man, today i have learned _FileListToArray and a new macro never used, @CRLF

I'm going to make the GUI, see ya :)

Edited by johnmcloud

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

  • Similar Content

    • Mag91
      By Mag91
      Hey Everybody,
      as you know im on a very low autoit-level.
      My question is: How can i read all PDFs from a Folder wich is open and copy them to a Folder on a Desktop.
       
      The Folder wich contains the PDFs is variable Z:\Projektls\"*"*"*EVERYTIME ANOTHER ENDING"*"*"*"*"
      There can be 1 PDF or even 15 PDFs.
      i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language
       
      THANKS!
       
    • galan2015
      By galan2015
      Hello, i have question. How put data from _FileListToArray to Combo ?
      I want fill combo with names of files from folder.
    • AutID
      By AutID
      This is more tricky than I thought it would be. I have been searching for some time now and can't seem to find an answer.
      To find the IE history manually I go to "C:UsersuserAppDataLocalMicrosoftWindowsHistory" and from there I select the subfolder(Today, Yesterday etc...) and check the files in it.
      So following this logic I came up with this which should normally work but it doesn't.

      #include <File.au3> #include <Array.au3> Local $File = RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "History" ) ;ConsoleWrite($File & @LF) Local $hSearch = _FileListToArray($File, Default, Default, True) _ArrayDisplay($hSearch) It returns some other files besides the Today, Yesterday folders.
      I assume this happens because they are not actually folders however since FileListToArray second parameter is set to default, which means all files if I understand correctly, then it should also return the paths of theToday folder.
      Anyone any ideas on this?
    • Alexxander
      By Alexxander
      Hi 
      I'am trying to list files from folder sorted by name (same as the picture)

      i tried this code
      #include <File.au3> $arr = _FileListToArray("D:\2") _ArrayDisplay($arr) i am getting this result
       

      Any one could explain why it is putting 10-1 before 8-1 ?
      how can i make Autoit view file same as windows explorer ?
    • Silverlode
      By Silverlode
      Hi everyone,
      I've got a bit of code that gets the file name of a zip file in a particular directory and tried to unzip it.  _FileListToArray should create an array and define $aArray[1] as the first file returned by the search.  But when I try to use $aArray[1] for anything, I get the error: "==> Array variable has incorrect number of subscripts or subscript dimension range exceeded."
      Any thoughts?
      If $osbit = "32" Then Local $aFileList = _FileListToArray($extract_dir, "*win32*") _ExtractZip($extract_dir & $aArray[1], $extract_dir) ElseIf $osbit = "64" Then Local $aFileList = _FileListToArray($extract_dir, "*amd*") _ExtractZip($extract_dir & $aArray[1], $extract_dir) EndIf Thanks.