Jump to content

Recommended Posts

Posted

I know there is _FileListToArrayRec()

but in help FIle you can read:
Despite the name, this UDF is iterative, not recursive.

and of course I mean real recursive.

I need to find all PDF files in all subfolders.

Do you know any solution ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I doubt it is possible in pure AutoIt, because of the stack overflow error. The interpreter will at some point stop recursive function calls to prevent stack overflow :unsure:. A reliable way of doing this would be to use Windows API (Win32, WMI etc.)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

  • Moderators
Posted

mLipok,

There is a working recursive file listing script in the "Recursion" tutorial in the Wiki.

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:

  Reveal hidden contents

 

Posted
  On 11/9/2017 at 1:17 PM, mLipok said:

I need to find all PDF files in all subfolders.

Expand  

And _FileListToArrayRec doesn't do this already?

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!

  Reveal hidden contents

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

Posted
  On 11/9/2017 at 3:33 PM, BrewManNH said:

And _FileListToArrayRec doesn't do this already?

Expand  

No

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 11/9/2017 at 3:33 PM, Melba23 said:

mLipok,

There is a working recursive file listing script in the "Recursion" tutorial in the Wiki.

M23

Expand  

Thank you. I will look there.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

@mLipok, to my experience, the iterative method is by far faster than the recursive one (some 30%-50% faster). and if _FileListToArrayRec does not do what you want, there must be a malfunction somewhere, because it is supposed to. this works for me:

#include <File.au3>
#include <Array.au3>
Global $aResult = _FileListToArrayRec('D:\', '*.pdf', $FLTAR_FILES, $FLTAR_RECUR)
_ArrayDisplay($aResult)

 

Edited by orbs

Signature - my forum contributions:

  Reveal hidden contents

 

Posted

Ps?

local $Dir , $File

_PsFileSearch_Rec("C:\Users" , "*.pdf")

Func _PsFileSearch_Rec($Dir , $File)
    run('cmd /k "powershell "dir -Path ' & $Dir & ' -Filter ' & $File & ' -Recurse" | %{$_.FullName}')
EndFunc ;PsFileSearch_Rec

 

  Reveal hidden contents

Posted
  On 11/9/2017 at 4:56 PM, iamtheky said:

Ps?

Expand  

Now you're just showing off. :thumbsup:

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!

  Reveal hidden contents

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

  • Moderators
Posted

mLipok,

I did not realise from your initial post you felt that _FileListToArrayRec does not function correctly in your specific case. As the author of the function, could I ask for more details of why you believe this to be true and sight of the code that you used.

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:

  Reveal hidden contents

 

Posted (edited)

In case you cared, I found this code on Stack Exchange for searching with C#, check it... fast searching. Uses Threading to parallelise the search! I love that site. You could modify it to return an array or whatever.

I made it a console app. you give it a drive followed by a space then the file type, you can use wildcards.

such as ConsoleApp1 C:\ *.pdf and watch it fly! just need to add a try/catch to catch when the access to a given path is denied by security, you can pipe that to a file once you sort that out and then you could read your file into an array, or just use this from AutoIt, adding in the trap for access denied. also needs to check that you passed parameters before running. lol. samples.

 

 

Program.cs

Edited by Earthshine
updated source to check for arguments passed, also, if you target .NET 4.6.2 there is no MaxPath errors

My resources are limited. You must ask the right questions

 

Posted
  On 11/9/2017 at 6:26 PM, Melba23 said:

mLipok,

I did not realise from your initial post you felt that _FileListToArrayRec does not function correctly in your specific case. As the author of the function, could I ask for more details of why you believe this to be true and sight of the code that you used.

M23

Expand  

Sure give me few hours .

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I just edited the above c# program and ran it to find all dlls on c:\ and tested it against a Command Prompt with a stopwatch

CMD = 58 sec

my app = 32 seconds

fast.

Edited by Earthshine
did an average of time tests

My resources are limited. You must ask the right questions

 

Posted

can we see the code for your test? I am surprised the improvement was only double. 

  Reveal hidden contents

Posted (edited)

here. i posted it as a download link above too. on my home notebook it runs great, 20 secs to find all dlls vs 60.

my first test was on a build machine with MANY thousands of DLLs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
    class Program
    {

        public static void Main(string[] args)
        {
            if (args.Length < 2 )
            {
            Console.WriteLine(value: "ERROR: args = null please provide a path and a file specification to search for.");
            Console.WriteLine(value: "Example: list c:\\ *.dll");
        }
        else
            {
               DirectoryInfo testdr = new DirectoryInfo(path: args[0]);
               WalkDirectoryTree(testdr, searchname: args[1]);
            }
        }
    
    public static void WalkDirectoryTree(DirectoryInfo dr, string searchname)
    {
        System.IO.FileInfo[] files = null;
        DirectoryInfo[] subDirs = null;
        try
        {
            files = dr.GetFiles(searchname);
        }
        catch (Exception ex)
        {
            //Console.WriteLine(ex.Message);
        }

        if (files != null)
        {
            foreach (FileInfo fi in files)
            {
                string dir = fi.DirectoryName;
                string file = fi.ToString();
                Console.WriteLine(value: dir + file);
            }
            subDirs = dr.GetDirectories();

            Parallel.ForEach(subDirs, dir => WalkDirectoryTree(dir, searchname));
        }
    }

    public override bool Equals(object obj)
    {
        return base.Equals(obj);
    }

    public override int GetHashCode()
    {
        return base.GetHashCode();
    }

    public override string ToString()
    {
        return base.ToString();
    }
}

 

Edited by Earthshine
check for arguments

My resources are limited. You must ask the right questions

 

Posted (edited)

here is the whole project so you don't need to fart around. mind you, this was 100 percent googled code off of StackOverflow... lol i try not to reinvent wheels. You can get a free Visual Studio 2017 to run this, heck I bet you could do it with Visual Code, also free and adorable. love that program.

use the Debug exe, was last one compiled... lol

 

ConsoleApp1.zip

Edited by Earthshine
check for arguments, targets .Net 4.6.2 so no Maximum path bullcrap

My resources are limited. You must ask the right questions

 

Posted (edited)
  On 11/9/2017 at 8:14 PM, mLipok said:

Sure give me few hours .

Expand  

little late...

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

Global $g_sTestingDir = @ScriptDir & '\TEST_DIR_FOR_PDF_LIST ' & @YEAR & '-' & @MON & '-' & @MDAY

_Example_CreateTestingEnvironment()
_Example_TryingToFindFiles()

Func _Example_CreateTestingEnvironment()
    if FileExists($g_sTestingDir) then Return

    Local $aSubdirs[4] = ['Katowice', 'Warszawa', 'Kraków', 'Ostrowiec Świętokrzyski']
    For $iDir_idx = 0 To UBound($aSubdirs) - 1
        DirCreate($g_sTestingDir & '\' & $aSubdirs[$iDir_idx])
        For $iFile_idx = 1 To 9
            FileWrite( _
                    $g_sTestingDir & '\' & $aSubdirs[$iDir_idx] & '\' & _
                    $iFile_idx & '__' & @HOUR & @MIN & @SEC & '.' & @MSEC & '.pdf' _
                    , '')
        Next
    Next

EndFunc   ;==>_Example_CreateTestingEnvironment

Func _Example_TryingToFindFiles()
    Local $aPDFFileList = _FileListToArrayRec($g_sTestingDir, '*.pdf', $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
    If @error Then MsgBox($MB_ICONERROR, '_FileListToArrayRec()', '@error = ' & @error & @CRLF & '@extended = ' & @extended)

    _ArrayDisplay($aPDFFileList, '$aPDFFileList')
EndFunc   ;==>_Example_TryingToFindFiles

EDIT1: Example changed

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

That example works fine for me (as I would expect) and I get all 36 pdf files returned. What do you see?

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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