Help on Names Collision, Renaming mode.

Discuss and share scripts and script files...
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Help on Names Collision, Renaming mode.

Post by SkyFrontier »

I'd like this:

Code: Select all

::new "Links_<curfolder>_<date yyyy-mm-dd>.txt", file, ,; rename s, "__/_", r;
to avoid name collision by appending a number suffix and getting the file ready in rename mode.
Can someone please help...?
Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

Suggestion: parameter to set the caret position when entering rename mode, since now we have a three state control switch.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

Current workaround:

Code: Select all

::new "Links_<curfolder>_<date yyyy-mm-dd_hh^nn%ss>.txt", file, ,; rename s, "^/h"; rename s, "%/min"; rename s, "__/_"; open <curitem>
-to whom it may concern... 8)

-but I'd prefer this having the "Links_<curfolder>_<date yyyy-mm-dd.txt" format, renaming "__/_" when occurring, appending numbers on name collision and ready in rename mode (3-state define-able, when implemented)...
...any ideas?
Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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

Re: Help on Names Collision, Renaming mode.

Post by TheQwerty »

So given <curfolder> = "A__TEMP__FOLDER" you want to create a text file named "Links_A_TEMP_FOLDER_2010-08-26_11h39min42.txt" ??

Try:

Code: Select all

new "Links_" . RegexReplace("<curfolder>","_+","_") . "_<date yyyy-mm-dd_hh\hnn\mi\nss>.txt";open "<curitem>";

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

No, no...
The hh-nn-ss/"open" thing is a workaround.
As above stated,
-but I'd prefer this having the "Links_<curfolder>_<date yyyy-mm-dd.txt" format, renaming "__/_" when occurring, appending numbers on name collision and ready in rename mode (3-state define-able, when implemented)...
So I can have:
Links_Temp_2010-08-26-01.txt
waiting in RENAMING mode, not open.
-but best of all would be using the writefile function, so it could grab clipboard and paste its contents into the newly created file. Simple solution to replace CTRL+SHIFT+N in specific, casual usage.
Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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

Re: Help on Names Collision, Renaming mode.

Post by TheQwerty »

Sorry, I can't be of further assistance since I don't understand what exactly you're trying to achieve.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

I'm trying to emulate "Paste Text Into New File (CTRL+ALT+V)" but with some level of customization, in ways current "Copy here with date" does. ^^
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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

Re: Help on Names Collision, Renaming mode.

Post by TheQwerty »

SkyFrontier wrote:I'm trying to emulate "Paste Text Into New File (CTRL+ALT+V)" but with some level of customization, in ways current "Copy here with date" does. ^^
So you want to create a file using the clipboard as its contents.
The name of this file should be: "Links_<curfolder>_yyyy-mm-dd-##.txt"
Where <curfolder> is the current folder name but with '__' collapsed to a single '_'.
And '-##' is an auto-incrementing suffix number used on collision.

And ideally after that you'd be put into rename mode and the cursor will be magically positioned using a scripting command that doesn't currently exist.

Is that correct?

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

lol
All is right, except of course for the "...the cursor will be magically positioned using a scripting command that doesn't currently exist" part, that I entered as a suggestion to Don when/if he sees this.
The "__>_" is because I have several folders whose names starts with underscores, and the newly created file doesn't need to reflect that.
"-##" (assuming it's an on-name-collision numbering) is necessary because I have tons of files to deal with and if such "index file" (that's what I'm intending with this thing!) already exists for another bunch of files, it'll be just a matter of renaming it to something else - reason why the "rename mode" invoked is important.
Thank you, TheQwerty!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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

Re: Help on Names Collision, Renaming mode.

Post by TheQwerty »

Okay, I think this should work...

Code: Select all

"Do Stuff"
	// Filename before the (possible) suffix.
	$prefix = 'Links_' . RegExReplace("<curfolder>", '_+', '_') . "_<date yyyy-mm-dd>";

	// Filename after the (possible) suffix.
	$ext = '.txt';

	/* Use the user defined suffix pattern.
	 * Note that the value is taken from the config file,
	 * which means if it has changed since last saved
	 * those changes will not be reflected here.
	 * You could call SaveSettings(); or #193; here to fix that.
	 */
	$suffix = GetKey('PostfixNum','General');

	/* This splits the pattern into three parts
	 * pre: Anything before the last set of zeros.
	 * zed: The last set of zeros.
	 * suf: Anything after the last set of zeros.
	 */
	$suffix = RegExReplace("$suffix", '^(.*?[^0]?)(0+)([^0]*)$', "$1<crlf>$2<crlf>$3");
	$suffix_pre = GetToken("$suffix", 1, "<crlf>");
	$suffix_zed = GetToken("$suffix", 2, "<crlf>");
	$suffix_suf = GetToken("$suffix", 3, "<crlf>");
	$suffix = '';

	// Check for collisions and increment suffix pattern.
	$min_lead = StrLen("$suffix_zed");
	$i = 0;
	while (Exists("<curpath>\$prefix$suffix$ext") != 0) {
		$i = $i + 1;
		$suffix = "$suffix_pre" . StrRepeat('0', $min_lead - StrLen("$i")) . "$i$suffix_suf";
	}

	// Write clipboard's contents to file.
	$err = WriteFile("<curpath>\$prefix$suffix$ext", "<clipboard>", 'n');
	End($err != 1, "Could not write file:<crlf>$prefix$suffix$ext");
This will use the suffix pattern that was last saved to XYplorer.ini (or whatever the current INI file is) when needed.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

Local term to describe this:
"Nussssss!!!"
:D
Yeah, now I have a tweak-able way to create .txt containing source paths of online resources, with a single keystroke and error-proof.
-trying to get the newly created thing selected and in rename mode. No go. :cry:
Tried something like

Code: Select all

focus $err
at the end of it but fails.
Anyway, the major part of the stuff is done.
Thank you!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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

Re: Help on Names Collision, Renaming mode.

Post by TheQwerty »

$err contains an error code which is a combination of 0, 1, and 2 OR-ed and Focus() uses a set of valid letters to focus a given control (not an item within a control)... A quick glance at the documentation for either command would have told you it wasn't going to work. ;)

At the very bottom after the End() you could use:

Code: Select all

SelFilter("$prefix$suffix$ext");
Focus('L');
#172; //File -> Rename

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

(Previously) Tried the "$prefix$suffix$ext" (without parenthesis) and not worked.
Using the code you told completely broke the script - it was generating the files but strangely not allowing showing then in the list. Experimentally disabling the "Focus('L');" did the same thing. Executing script again WITHOUT the new code creates a new file and refreshes list, allowing to see all previous attempts' files.
Thanks for trying.

EDIT: -yes, I've added the extra blank spaces before each line to match scripting rules. Just in case.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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

Re: Help on Names Collision, Renaming mode.

Post by TheQwerty »

Do you have auto-refresh enabled?

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help on Names Collision, Renaming mode.

Post by SkyFrontier »

Yes, I do.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply