Page 1 of 1

Quicksearch files only

Posted: 24 Jun 2021 20:26
by Ghosty
Return all matching files in subfolders?

This includes folders named with ".txt" ....

Code: Select all

$findext="*.txt;*.pdf";
$found=quicksearch($findext, <curpath>);
  msg "Found...<br>" . $found,0;

Re: Quicksearch files only

Posted: 24 Jun 2021 20:29
by admin
Use switch /f to find only files:

$findext="*.txt;*.pdf /f";

Re: Quicksearch files only

Posted: 24 Jun 2021 20:29
by highend

Code: Select all

$findext="*.txt;*.pdf";
$found=quicksearch($findext . " /f", <curpath>);

Re: Quicksearch files only

Posted: 24 Jun 2021 20:31
by Ghosty
ok so just add /f once, Thanks!

BTW /f is not in the chm.

Re: Quicksearch files only

Posted: 24 Jun 2021 20:34
by highend
Ofc it is

Main Topics - Quick Search - Search Pattern Switches

Re: Quicksearch files only

Posted: 24 Jun 2021 20:52
by Ghosty
From my CHM dated Wednesday, ‎April ‎7, ‎2021, ‏‎3:00:00 PM
20210624 chm no f-2.jpg
20210624 chm no f-1.jpg

Re: Quicksearch files only

Posted: 24 Jun 2021 21:19
by highend
Read my last post again...

Re: Quicksearch files only

Posted: 24 Jun 2021 22:44
by Ghosty
You did! Thanks!

This is the script, seems to work. It moves any txt/pdf from subfolders into the current folder.

Code: Select all

"Move Here from Subfolders - txt/pdf"
	$moveext="*.txt;*.pdf;";
	$movefiles = quicksearch($moveext . " /f", <curpath>);
	// msg "Found:<br>" . $movefiles, 0;
	foreach($movefile, $movefiles, <crlf>, "e") {
		status "Moving " . gpc($movefile, "file") . " ...", , "progress";
		$movebase=gpc($movefile,"path");
		// same $gpc($movefile,"component", -2, 1);
		if ($movebase != "<curpath>") {
			// $m="moveto(<br>curpath=<curpath>";
			// $m="$m <br>movefile=$movefile";
			// msg $m,0;
			moveto(<curpath>,$movefile);
		}
		
	}
I put this in a file %appdata%\XYplorer\Scripts\MoveHere_FromSub_txtpdf.xys and added a user-button to the toolbar,
On left click:

Code: Select all

load "MoveHere_FromSub_txtpdf.xys"
On right click:

Code: Select all

run  '"C:\Program Files\Notepad3\Notepad3.exe"  "%appdata%\XYplorer\Scripts\MoveHere_FromSub_txtpdf.xys"'  ;

Re: Quicksearch files only

Posted: 24 Jun 2021 23:06
by highend
You could probably save a lot of time by moving all those items in one go...

Code: Select all

    $moveExts  = "*.txt;*.pdf";
    $moveFiles = quicksearch($moveExts . " /f");
    // Remove all items that are already in this path
    $escaped   = regexreplace(<curpath>, "([\\.+(){\[^$])", "\$1");
    $moveFiles = regexreplace($moveFiles, "$escaped\\[^\\]+?(\r?\n|$)");
    if ($moveFiles) { moveto , $moveFiles, , 1, 2, 2; }
And by the way, XY has inbuilt variables, so:

Code: Select all

run  """C:\Program Files\Notepad3\Notepad3.exe"" ""<xyscripts>\MoveHere_FromSub_txtpdf.xys""";
would work as well and is agnostic about where you store the script files...