Help needed with a tiny script!
Posted: 03 Aug 2011 20:39
Hi all,
I've been having some success with some very simple but amazingly useful scripts, but there's one little job I'd love to be able to do and the solution escapes me every time . . .
I'm trying to write a script to take the size of selected folders (directories) in the list view and copy the folder size to the comment field. It should be so SIMPLE but it's driving me MAAAAAADDD!!!
Anyway, heres what I've done so far:
This works for one (and only one) selected directory. Useful, yes, but not quite there yet. So I've been looking at using a 'foreach' loop to take the selected directories and tag the comment field for each. I've tried a few things, but this is my latest attempt:
Now, what happens here is that the selected folders are listed correctly in the variable $Files. Each appears to be stepped through, but the result is that all of the folder sizes are concatenated together and each of the selected folders gets the comment field tagged with ALL of the folder sizes i.e. the comment field looks like this:
I just look at this code and I feel that I'm using the 'foreach' command in completely the wrong way, but whatever I try I can't seem to figure this.
Having tried several times I know I'm on the wrong track here. Can anyone advise and adjust this code so it get's closer to the desired outcome?
Thanks for any advice
Biggy
I've been having some success with some very simple but amazingly useful scripts, but there's one little job I'd love to be able to do and the solution escapes me every time . . .
I'm trying to write a script to take the size of selected folders (directories) in the list view and copy the folder size to the comment field. It should be so SIMPLE but it's driving me MAAAAAADDD!!!
Anyway, heres what I've done so far:
Code: Select all
#431; // Toggle showing folder sizes
$size = (report("{Size GB}",1)); // Get the size of the folder
tag "$size", , 2; // Set the size in the comment field
#431; // Toggle off showing folder sizes
savesettings; // So I don't lose my comments when I exit XY!
Code: Select all
#431; // Toggle showing folder sizes
$Files = get("SelectedItemsPathNames", "|");
foreach($file, $Files, "|") {
$size = ""; // Reset the variable I'll use as a container for the size
$size = (report("{Size GB}",1)); // Get the size of the folder or file
tag "$size", , 2; // Set the size in the comment field
}
#431;
savesettings;
Code: Select all
6.7GB3.4GB2.9GB5.8GB etc etc
Having tried several times I know I'm on the wrong track here. Can anyone advise and adjust this code so it get's closer to the desired outcome?
Thanks for any advice
Biggy