Jump to content

_FileListToArray versus _FileListToArrayRec


mr-es335
 Share

Recommended Posts

Good day,

A query...if I may..."Can _FileListToArray not be deployed in the same manner as _FileListToArrayRec?"

For example...from this...

#include <Constants.au3>
#include <File.au3>

example()

Func example()
    Local $aFiles[0]
    $aFiles = _FileListToArrayRec("C:\RML\SAC\VST_PlugIns", "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    For $i = 1 To $aFiles[0]
        FileDelete($aFiles[$i])
    Next
EndFunc   ;==>example

...to this...

#include <Constants.au3>
#include <File.au3>

example()

Func example()
    Local $aFiles[0]
    $aFiles = _FileListToArray("C:\RML\SAC\VST_PlugIns", "*", $FLTAR_FILES)
    For $i = 1 To $aFiles[0]
        FileDelete($aFiles[$i])
    Next
EndFunc   ;==>example

The former works, whilst the latter does not work.

Thanks!

Edited by mr-es335
Link to comment
Share on other sites

What does "does not work" exactly mean? Do you get no result, missing data, error code ...?
The more information you can provide the easier it is for us to help you :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

water,

This example does absolutely nothing!

#include <Constants.au3>
#include <File.au3>

example()

Func example()
    Local $aFiles[0]
    $aFiles = _FileListToArray("C:\RML\SAC\VST_PlugIns", "*", $FLTAR_FILES)
    For $i = 1 To $aFiles[0]
        FileDelete($aFiles[$i])
    Next
EndFunc   ;==>example

 

Link to comment
Share on other sites

in the former
you have the parameter $FLTAR_FULLPATH

in the latter not
and you don't give proper path

FileDelete("C:\RML\SAC\VST_PlugIns\" & $aFiles[$i])

Edit:
try and you will see

#include <Constants.au3>
#include <File.au3>

example()

Func example()
    Local $aFiles[0]
    $aFiles = _FileListToArray("C:\RML\SAC\VST_PlugIns", "*", $FLTAR_FILES)
    For $i = 1 To $aFiles[0]
;~         FileDelete($aFiles[$i])
        ConsoleWrite($i & ") FileDelete: " & $aFiles[$i] & @CRLF)
    Next
EndFunc   ;==>example

 

Edit:
The right would be with $bReturnPath = True

#include <Constants.au3>
#include <File.au3>

example()

Func example()
    Local $aFiles[0]
    
    ;_FileListToArray ( $sFilePath [, $sFilter = "*" [, $iFlag = $FLTA_FILESFOLDERS [, $bReturnPath = False]]] )

    $aFiles = _FileListToArray("C:\RML\SAC\VST_PlugIns", "*", $FLTAR_FILES, True)
    For $i = 1 To $aFiles[0]
;~         FileDelete($aFiles[$i])
        ConsoleWrite($i & ") FileDelete: " & $aFiles[$i] & @CRLF)
    Next
EndFunc   ;==>example

or without $bReturnPath = True  which entails with  $bReturnPath = False

#include <Constants.au3>
#include <File.au3>

example()

Func example()
    Local $aFiles[0]
    
    ;_FileListToArray ( $sFilePath [, $sFilter = "*" [, $iFlag = $FLTA_FILESFOLDERS [, $bReturnPath = False]]] )

    $aFiles = _FileListToArray("C:\RML\SAC\VST_PlugIns", "*", $FLTAR_FILES)
    For $i = 1 To $aFiles[0]
;~         FileDelete($aFiles[$i])
        ConsoleWrite($i & ") FileDelete: " & "C:\RML\SAC\VST_PlugIns\" & $aFiles[$i] & @CRLF)
    Next
EndFunc   ;==>example

 

which could also be done with _FileListToArrayRec
with changing the parameter  $iRecur from $FLTAR_RECUR  to  FLTAR_NORECUR

#include <Constants.au3>
#include <File.au3>

example()

Func example()
    Local $aFiles[0]
    $aFiles = _FileListToArrayRec("C:\RML\SAC\VST_PlugIns", "*", $FLTAR_FILES,  $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
    For $i = 1 To $aFiles[0]
        FileDelete($aFiles[$i])
    Next
EndFunc   ;==>example

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

One of my coding rules is to check the return value or error code after each call of an AutoIt function.
FileDelete returns 1 on success and 0 if there was a problem.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...