prune dir
-
- Posts: 61
- Joined: 22 Nov 2009 21:28
prune dir
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.
It seems this is a perfect job for the file manager.
Thoughts?
Thanks.
Re: prune dir
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
How to execute an Script: http://88.191.26.34/XYwiki/index.php/Ca ... Script_.3F
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;
Last edited by Stefan on 21 Mar 2010 00:33, edited 4 times in total.
-
- Posts: 61
- Joined: 22 Nov 2009 21:28
Re: prune dir
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"?
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
You are welcome. I edited the script above. Done?jayfischer wrote:except for a few things.
-
- Posts: 61
- Joined: 22 Nov 2009 21:28
Re: prune dir
Done! If works perfect now!!
Thanks again, Stefan.
Thanks again, Stefan.
Re: prune dir
can work with multi selected folders?
Re: prune dir
Code: Select all
//move contents of each selected dir up one level
foreach($token, <get selecteditemspathnames |>) {
moveto "<curpath>", "$token\*.*";
}
Re: prune dir
Then check if there is a selection before trying to move something?
One of my scripts helped you out? Please donate via Paypal
Re: prune dir
well what about small confirm before execute the script
something like that: are you sure yes or no
_________
found it..thanks highend
something like that: are you sure yes or no
_________
found it..thanks highend
Re: prune dir
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
not sure if i understood you correctlyTheQwerty 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\*.*"; }
the result of executing above script while nothing selected;move system files from c to current folder
- Attachments
-
- 2014-10-30_085427.png (41.68 KiB) Viewed 2187 times
Re: prune dir
I dropped a comma, there should be three in a row - above script is corrected.yusef88 wrote:not sure if i understood you correctly
Check the documentation:
Code: Select all
help('idh_scripting.htm#idh_scripting_foreachloops');
Re: prune dir
works only with one selected folder..thanks