Page 1 of 1

prune dir

Posted: 20 Mar 2010 15:16
by jayfischer
Sometimes I would like the ability to prune a directory (move the files up a level and then delete the directory). I do this manually now by selecting all the files and dropping them in the parent dir and then deleting the now empty directory.

It seems this is a perfect job for the file manager.

Thoughts?

Thanks.

Re: prune dir

Posted: 20 Mar 2010 15:41
by Stefan
Script?

Pseudo code
$curr = <curfolder> where i am in right now
  sel all;
  move to ".."
  goto ".."
  del $curr

or better:
$curr = <curitem> folder i have selected
  goto $curr
  sel all;
  move to ".."
  goto ".."
  del $curr

Code: Select all

 
  //to be sure, set focus explicitly to list and current active pane:
  focus;

  //note: this script works only for one folder on each run:
  end (getinfo("CountSelected")>1), "Please select ONE folder only, script will end now";

  //now check if selected item is an FOLDER or not:
  $IsFolder = report("{Dir Yes|No|Drive}",1);
  //if the item isn't an folder cancel the whole script:
  end ("$IsFolder"!="Yes"), "He!, you did not really have select an FOLDER, script will end now";

  //store name of selected folder into an variable named $curr:
  $curr = <curitem>; 

  //msg to ask the user if he really wants this action:
  // (When you press "Cancel", the script execution will end)
  msg "Do you really want to prune<crlf>$curr ?<crlf><crlf>Click OK to prune now.",1;

  //go inside that selected folder:
  goto $curr; 

  //select items:
  //sel f;  //means: Select all files (no folders). 
  //sel a;  //means: Select all items in there (files and folders)
    sel a; 

  
  /* disable optional function
  //Rename items with parent folder name first before moving?:
  $ren = confirm("Rename items with parent folder name first?");
  IF ($ren==1){
  $files = gettoken("SelectedItemsNames", "|");
  rename b, '<curfolder>_*', $files; 
  }
  */


  //move all selected one level up to parent folder:
  moveto ".."; 
  
  //go up one level to parent:  (is not needed, XY goes to parent at its own on deleting $curr)
  //goto "<curpath>\.."; 
  
  //delete the above selected folder $curr:
  //delete [recycle=1], [confirm], [itemlist] - just the syntax as reverence 
  delete 1,1, $curr; 
How to execute an Script: http://88.191.26.34/XYwiki/index.php/Ca ... Script_.3F

Re: prune dir

Posted: 20 Mar 2010 20:57
by jayfischer
Stefan,

Again you come through with a script. It works great except for a few things.

Three items.

1. is it possible to check that a folder is selected (I accidentally hit the user button without a selection and it deleted the items in the current directory - not the child)

2. is there a way to bypass the "Are you sure you want to delete this folder?" dialog?

3. after deleting the folder go back to the parent

Thanks,
Jay

edit: I tweaked the script to fix #2 and #3 (with your superbly documented script)

edit2: Better yet for item 1 would be to ask the user if he is sure he wants to prune dir "c:\windows\system32"?

Re: prune dir

Posted: 20 Mar 2010 21:16
by admin
For #1 you may look at the exists() function.

Re: prune dir

Posted: 20 Mar 2010 21:53
by Stefan
jayfischer wrote:except for a few things.
You are welcome. I edited the script above. Done? :D

Re: prune dir

Posted: 21 Mar 2010 00:07
by jayfischer
Done! If works perfect now!!

Thanks again, Stefan.

Re: prune dir

Posted: 30 Oct 2014 14:25
by yusef88
can work with multi selected folders?

Re: prune dir

Posted: 30 Oct 2014 14:45
by yusef88

Code: Select all

//move contents of each selected dir up one level
 foreach($token, <get selecteditemspathnames |>) {
   moveto "<curpath>", "$token\*.*";
 }
very helpful script expect for it kind of dangerous because if nothing select it move items from c drive

Re: prune dir

Posted: 30 Oct 2014 15:01
by highend
Then check if there is a selection before trying to move something?

Re: prune dir

Posted: 30 Oct 2014 15:30
by yusef88
well what about small confirm before execute the script
something like that: are you sure yes or no
_________
found it..thanks highend

Re: prune dir

Posted: 30 Oct 2014 15:38
by TheQwerty
You should be able to just use the foreach loop's MsgOnEmpty parameter:

Code: Select all

foreach($token, <get selecteditemspathnames |>,,, 'Nothing selected') {
   moveto "<curpath>", "$token\*.*";
 }

Re: prune dir

Posted: 30 Oct 2014 15:56
by yusef88
TheQwerty wrote:You should be able to just use the foreach loop's MsgOnEmpty parameter:

Code: Select all

foreach($token, <get selecteditemspathnames |>,, 'Nothing selected') {
   moveto "<curpath>", "$token\*.*";
 }
not sure if i understood you correctly
the result of executing above script while nothing selected;move system files from c to current folder

Re: prune dir

Posted: 30 Oct 2014 16:19
by TheQwerty
yusef88 wrote:not sure if i understood you correctly
I dropped a comma, there should be three in a row - above script is corrected.

Check the documentation:

Code: Select all

help('idh_scripting.htm#idh_scripting_foreachloops');

Re: prune dir

Posted: 30 Oct 2014 16:28
by yusef88
works only with one selected folder..thanks