running script on multiple files

Discuss and share scripts and script files...
Post Reply
slowe
Posts: 2
Joined: 14 Jan 2014 19:22

running script on multiple files

Post 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

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

Re: running script on multiple files

Post 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...
One of my scripts helped you out? Please donate via Paypal

slowe
Posts: 2
Joined: 14 Jan 2014 19:22

Re: running script on multiple files

Post 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

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

Re: running script on multiple files

Post 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;
		}
	}
To see the attached files, you need to log into the forum.

Post Reply