Looping Through Selected Items (w/ Examples)
Posted: 11 Aug 2008 18:10
Hey there,
Alright so in my daily XY scripting I always try to do what I need, even when it's not really/fully/natively supported. Sure, I can't do "onEvent scripting" (or whatever the official name for that feature will be, I keep forgetting
) on my own, but we can still do a couple of little things.
For example, using regexp we can deal with basic conditions and create loops. Putting this to use, I made a little script that will allow one to (hopefully) easily write scripts without worrying about the whole looping part.
Move all items in selected folder(s) to current folder
It should be easy enough : you first need to put in your "Scripts" folder the script file "Loop Through Selected Items.xys" ; and then in that folder you can use your own scripts like this one little script, which will ignore any selected file, but move the content of each of the selected folders into the current one. Here you go (MoveToCurrent.xys) :
See, looks pretty easy, doesn't it? 
Okay, for more about all of this and how it works, please see here.
To use this, you'll need to download the "looping script" (Loop Through Selected Items.xys) ; and for examples here's one ready-to-use file with the "move content of selected folder to current location" example above, and another one that will count how many files/folders are in each of the selected folders : CountMove.xys
Before I go, two important things :
- Please note that I wrote this script with the idea that all selected items where in the same folder, and it will not work otherwise. In other words, you should not try to use it from search results, because results would be unexpected ! You've been warned.
- For internal reasons, both the "Loop Through Selected Items.xys" and your own script file(s) should all be located under "<xydata>\Scripts\"
Hopefully this'll be helpful/useful to some...
Happy XY scripting!
Alright so in my daily XY scripting I always try to do what I need, even when it's not really/fully/natively supported. Sure, I can't do "onEvent scripting" (or whatever the official name for that feature will be, I keep forgetting
For example, using regexp we can deal with basic conditions and create loops. Putting this to use, I made a little script that will allow one to (hopefully) easily write scripts without worrying about the whole looping part.
Move all items in selected folder(s) to current folder
It should be easy enough : you first need to put in your "Scripts" folder the script file "Loop Through Selected Items.xys" ; and then in that folder you can use your own scripts like this one little script, which will ignore any selected file, but move the content of each of the selected folders into the current one. Here you go (MoveToCurrent.xys) :
Code: Select all
"Move all items in selected folder(s) to current folder"
setkey "MoveToCurrent", "File", "Load", "Loop Through Selected Items.ini";
setkey "move", "Name", "Load", "Loop Through Selected Items.ini";
load "Loop Through Selected Items", "_Start";
"_moveFile"
// do nothing
"_moveFolder"
moveto <curpath>, "<curpath>\<curname>\*";
"_moveDone"
status "Moving done";Okay, for more about all of this and how it works, please see here.
To use this, you'll need to download the "looping script" (Loop Through Selected Items.xys) ; and for examples here's one ready-to-use file with the "move content of selected folder to current location" example above, and another one that will count how many files/folders are in each of the selected folders : CountMove.xys
Before I go, two important things :
- Please note that I wrote this script with the idea that all selected items where in the same folder, and it will not work otherwise. In other words, you should not try to use it from search results, because results would be unexpected ! You've been warned.
- For internal reasons, both the "Loop Through Selected Items.xys" and your own script file(s) should all be located under "<xydata>\Scripts\"
Hopefully this'll be helpful/useful to some...
Happy XY scripting!