Page 1 of 1

running script on multiple files

Posted: 14 Jan 2014 20:35
by slowe
I am having a problem that I wonder if you could help me with.

I have a script:
::$date = regexreplace("<curbase>", ".+_(\d{4})(\d{2})(\d{2})_.+", "$1-$2-$3");
$time = regexreplace("<curbase>", ".+_.+_(\d{2})(\d{2})(\d{2})_.+", "$1:$2:$3");
timestamp cma, $date $time;

I am not sure how to save it, but it is in the script window. When I select one file it works. When I select 5 files it works. When I select all files (~25,000), it does not work.

Ideas? I cannot find anything in documentation on how to save scripts or how to run on selected files.

Thanks

Steve

Re: running script on multiple files

Posted: 14 Jan 2014 20:43
by highend
Create a file with the extension ".xys" and copy and paste your code (apart from the :: in front of the first line) into it. Save it. Invoke it (see the scripting menu...).

Do you really want to get the date / time from the focused file and apply this value to all other files?

If not, do it in a foreach loop.

Selecting 25k files will probably exceed the limit of the internal variable "itemlist" but that's only a rough guess...

Re: running script on multiple files

Posted: 14 Jan 2014 21:47
by slowe
highend-

Can you provide me with an example loop. I do not want it to be for the first file, but for each file.


Thanks

S

Re: running script on multiple files

Posted: 14 Jan 2014 21:55
by TheQwerty
This should work for you, but please verify on a small selection first.

Code: Select all

"Timestamp from Name"
	// Get the current selection.
	$sel = Get('SelectedItemsPathNames', "<crlf>", 'a');

	// For each item in the selection...
	foreach($item, $sel, "<crlf>",, 'Nothing is selected...') {
		// If the current item is empty go to next item.
		if ($item == '') { continue; }

		// Extract the base name.
		$base = GetPathComponent($item, 'base');

		// Extract the date and time.
		$date = RegexReplace($base, '.+_(\d{4})(\d{2})(\d{2})_.+', '$1-$2-$3');
		$time = RegexReplace($base, '.+_.+_(\d{2})(\d{2})(\d{2})_.+', '$1:$2:$3');

		// Only time stamp items if we can extract the date and time from the name.
		if ($date != $base && $time != $base) {
			// Set item's date and time.
			TimeStamp 'cam', "$date $time", $item;
		}
	}