Re: Command Number for "Copy Containing Folder(s)"?
Posted: 11 Sep 2014 23:08
A slightly changed version...
Tested on 26.547 files in 4.279 folders (SSD).
The last version needs 2350 msecs, the new one 1400, so a 40% increase in speed.
Most of it comes because of deriving the folder list of the $files variable instead of
processing a second folderreport().
The last version wasn't working correctly because it cut off parts of matching paths.
The new version adds a trailing pattern to avoid this.
Tested on 26.547 files in 4.279 folders (SSD).
The last version needs 2350 msecs, the new one 1400, so a 40% increase in speed.
Most of it comes because of deriving the folder list of the $files variable instead of
processing a second folderreport().
The last version wasn't working correctly because it cut off parts of matching paths.
The new version adds a trailing pattern to avoid this.
Code: Select all
$startingFolder = inputfolder("C:\", "Please select folder to search");
$excludedFiles = input("Enter the file name(s) that should NOT be in any of the folders", "File names must include their extension but NOT the path! Separate all items with a pipe '|'. Wildcards are not allowed!");
$files = folderreport("files", "r", $startingFolder, "r", , "<crlf>");
// Derive folders from $files (faster than an extra folderreport)
$folders = formatlist(regexmatches($files, "^.*(?=\\)", "<crlf>"), "dents", "<crlf>");
$metaCharacters = "(\\|\*|\^|\$|\.|\+|\(|\)|\[|\{)";
$escapedCharacters = "\$1";
$excludedFiles = regexreplace($excludedFiles, $metaCharacters, $escapedCharacters);
$matches = regexmatches($files, "^.*?(" . $excludedFiles . ")$", "<crlf>");
if ($matches) {
// Get everything in each line up to (but not including) the last backslash -> path component
$pattern = regexreplace(formatlist(regexmatches($matches, "^.*(?=\\)", "|"), "dents"), $metaCharacters, $escapedCharacters);
// To remove only full paths we have to add an additonal trailing pattern
// It omits the need for the formerly used formatlist at the end as well
$pattern = trim(regexreplace($pattern, "(\||$)", "(\r?\n|$)|"), "|", "R");
$folders = regexreplace($folders, "($pattern)");
}
text $folders;