Extracting files from a folder based on criteria in a file

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
4run
Posts: 2
Joined: 05 Jun 2014 17:28

Extracting files from a folder based on criteria in a file

Post 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.

highend
Posts: 14953
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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^^
One of my scripts helped you out? Please donate via Paypal

Post Reply