Jump to content

Recommended Posts

Posted

Inside a main directory I have many files, and I want to get a list of all files that simultaneously have the PDF extension (*.pdf) AND name beginning by an "A" (A*). Or either, I am trying to use a filter that has more than one component.

I could make 2 different scripts that use a filter with one-only component:

CODE
$path = "C:\Test"

$filter = "*.pdf"

$search = FileFindFirstFile ($path & "\" & $filter)

While $search = 1

$file = FileFindNextFile ($search)

If @error Then ExitLoop

MsgBox (0, "File Name", $file)

WEnd

CODE
#Include <File.au3>

#Include <Array.au3>

$path = "C:\Test"

$filter = "*.pdf"

$file_list = _FileListToArray ($path, $filter)

_ArrayDisplay ($file_list, "File List")

I tried

$filter = "A*" And "*.pdf"

But I got an error....

How can I use a filter that has more than one component?

Thanks in advance.

Best regards.

MLMK - my blogging craziness...
Posted

I don't know about using multiple filters. It is possible with other functions, like "FileOpenDialog" but it doesn't seem to work here.

Anyway, try this:

#include <File.au3>
#include <Array.au3>
$path = "C:\Test"
$filter = "*.pdf"
$search = _FileListToArray($path,$filter)
If IsArray($search) Then
    For $i=0 to $search[0]
        If StringLeft($search[$i],1)="A" Then
            MsgBox(0,"",$search[$i])
        EndIf
    Next
Else
    MsgBox(0,"Error","No files found")
EndIf
Posted (edited)

randallc - If I use:

$filter = "A*|*.pdf"

or

$filter = "A*"|"*.pdf"

I get the same error - @Error = 2 (Invalid $sFilter)

And if I write:

#include <_FileListToArrayNew2g.au3>

I get another error message - " ==> Error opening the file.: <_FileListToArrayNew2g.au3>

Nahuel - your code works fine! Thank you!

But how to do in order to use, for example, a filter with 4 components?

Filter_with_4_conditions = ((filename with the "A*" wildcard) AND (filename with the "*.pdf" wildcard) AND 10 < StringLen (filename) <22) AND (FileGetSyze > 4 MB))

I am trying to code a File Sorter by many parameters I specify...

Forgive my late post but I had a problem in my home and only now I am near my computer again. Your answer was very quick; thanks! Please do not abandon this question....

Thanks in advance!

Edited by asgarcymed
MLMK - my blogging craziness...
Posted

Now the script runs fine but the search results are not correctly restricted to the filters... Files must have its name beginning with an "A" (filter 1 = "A*" wildcard") and its extension (last letters after the last dot) must be txt (filter 2 = "*.txt" wildcard). I even tried (again; now with the new include file) -

$filter = "A*|*.pdf" (no error messages but the list is much bigger / inaccurate)

vs

$filter = "A*"|"*.pdf" (got error message - ==> Unable to parse line.: ).

It seems that this new file included <_FileListToArrayNew2g.au3> may have a bug; or it is my brain buggy?

Thanks for replying :)

MLMK - my blogging craziness...
Posted (edited)

Now the script runs fine but the search results are not correctly restricted to the filters... Files must have its name beginning with an "A" (filter 1 = "A*" wildcard") and its extension (last letters after the last dot) must be txt (filter 2 = "*.txt" wildcard). I even tried (again; now with the new include file) -

$filter = "A*|*.pdf" (no error messages but the list is much bigger / inaccurate)

vs

$filter = "A*"|"*.pdf" (got error message - ==> Unable to parse line.: ).

It seems that this new file included <_FileListToArrayNew2g.au3> may have a bug; or it is my brain buggy?

Thanks for replying :)

OK thanks,

I'll have a look; did you try the way I had tested?; "*.txt|A*"?

Thanks, Randall

Edited by randallc
Posted

$filter = "A*"|"*.pdf" (got error message - ==> Unable to parse

There's your mistake. It should be:

$filter = "A*|*.txt"

But you're right, it doesn't work...

I suppose you could just add more conditions to the code I gave you before... I don't know, just an idea..

#include <File.au3>
#include <Array.au3>
$path = "C:\"
$filter = "*.ini"
$search = _FileListToArray($path,$filter)
If IsArray($search) Then
    For $i=0 to $search[0]
        If StringLeft($search[$i],1)="A" Then
            If (10>StringLen($search[$i])) And (StringLen($search[$i])>20) Then
                MsgBox(0,"",$search[$i])
            EndIf
        EndIf
    Next
Else
    MsgBox(0,"Error","No files found")
EndIf
Posted (edited)

$filter = "A*|*.txt"

But you're right, it doesn't work...

Hi,

Maybe rem out this line till I think about it! - It works again this way.. [about line 47 in UDF]

;~  $sFilter = StringReplace("*" & $sFilter & "*", "**", "*")
Best, randall

[PS You can be more specific also if you use ArraySearch, arrayFindAll - 1helpfile, 2search ultima]

Edited by randallc
Posted

After many hours of brain working, I could improve my knowledge a lot! And the help you gave me was very, very important! So I want to "say louder" - THANK YOU!!!

;)

:)

MLMK - my blogging craziness...

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
×
×
  • Create New...