prune dir

Features wanted...
Post Reply
jayfischer
Posts: 61
Joined: 22 Nov 2009 21:28

prune dir

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

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: prune dir

Post 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
Last edited by Stefan on 21 Mar 2010 00:33, edited 4 times in total.

jayfischer
Posts: 61
Joined: 22 Nov 2009 21:28

Re: prune dir

Post 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"?

admin
Site Admin
Posts: 60624
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: prune dir

Post by admin »

For #1 you may look at the exists() function.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: prune dir

Post by Stefan »

jayfischer wrote:except for a few things.
You are welcome. I edited the script above. Done? :D

jayfischer
Posts: 61
Joined: 22 Nov 2009 21:28

Re: prune dir

Post by jayfischer »

Done! If works perfect now!!

Thanks again, Stefan.

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: prune dir

Post by yusef88 »

can work with multi selected folders?

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: prune dir

Post 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

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

Re: prune dir

Post by highend »

Then check if there is a selection before trying to move something?
One of my scripts helped you out? Please donate via Paypal

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: prune dir

Post by yusef88 »

well what about small confirm before execute the script
something like that: are you sure yes or no
_________
found it..thanks highend

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: prune dir

Post 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\*.*";
 }

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: prune dir

Post 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
Attachments
2014-10-30_085427.png
2014-10-30_085427.png (41.68 KiB) Viewed 2187 times

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: prune dir

Post 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');

yusef88
Posts: 1126
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: prune dir

Post by yusef88 »

works only with one selected folder..thanks

Post Reply