Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

using wildcard *. with pathmatchspec to filter files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • using wildcard *. with pathmatchspec to filter files

    To solve an error in filtering files using the wildcard *. in the windows api command PathMatchSpecA.
    PathMatchSpecA is mostly used in programs that list a directory(folder) and its subdirectories(subfolders)


    There are a few programs that retrieve all files and directories from a directory using the wildcard *.* with the dir$ command and then filter(scrub) the files needed with a filter string using PathMatchSpecA

    I had trouble not getting the files that had no period like "paul" or files with nothing on the right of the period like "paul." using PathMatchSpecA.

    Below is my solution that solved my problem.

    After adding the two extra lines of code, you can get the files with a filter string such as "p*." will return p, paul123, pp, pdp. and filter string "*." will now retrieve all files without a single period in them.

    If speed is an issue, a few integer variables used as flags could be created to speed this operation up.

    add two lines below
    code:
    Code:
    'a declaration at the first part of the program
    DECLARE FUNCTION PathMatchSpec LIB "SHLWAPI.DLL" ALIAS "PathMatchSpecA"(pszFile AS ASCIIZ, pszSpec AS ASCIIZ) AS LONG
    
    'further into your program
    '
    '
    'add the next line
    IF RIGHT$(filter,2)="*." THEN IF INSTR(FILENAME,".")=0& THEN FILENAME=FILENAME+"."
    
    'the next line would already be in your code
    IF PathMatchSpec(BYVAL STRPTR(FileName), BYVAL STRPTR(Filter)) THEN dosomething  ' if the filter matched your filename then answer is true
    
    'add the next line
    IF RIGHT$(filename,1)="." THEN filename=LEFT$(filename,(LEN(filename)-1))
    Last edited by Paul Purvis; 21 Dec 2007, 07:52 PM.
    p purvis
Working...
X