Page 1 of 1

Extracting files from a folder based on criteria in a file

Posted: 05 Jun 2014 17:35
by 4run
Dear colleagues,

I am new to the forum and have started using Xy. I want to be able to select certain named pdf files from a folder based on the first name of the file which would be in a list that I can nopy to clipboard/put on text file or excel.

I am hoping the gods out there can explain this for me. I have high hopes in being able to do this as it will save me my job.

Re: Extracting files from a folder based on criteria in a fi

Posted: 05 Jun 2014 19:10
by highend
There is not really much information about the file names so...

Code: Select all

    $names = regexmatches("<clipboard><crlf>", "^.*?(?=\s)", "|");
    foreach($item, listfolder("<curpath>", "*.pdf", 5), "|") {
        $firstPart = regexreplace($item, "(^.*?(?=\s)).*", "$1");
        foreach($name, $names, "|") {
            if ($name LikeI $firstPart) {
                selectitems $item, , , "a";
            }
        }
    }
    
Go into the folder that contains the .pdf files.
Copy the list of names into the clipboard (each name must be on it's own line!)
Execute this script.

It _should_ select the necessary files.

The delimiter between the first and the second part of a filename has to be a space / tab.

And yes, coded in a hurry^^