Help on Names Collision, Renaming mode.

Discuss and share scripts and script files...
TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Help on Names Collision, Renaming mode.

Post by TheQwerty »

Meh... here's a hack that will keep trying...

Code: Select all

   Focus('L');
   Sel();
   $i = 0;
   while (GetInfo('CountSelected') == 0 and $i < 1000000000) {
      Sel("[$prefix$suffix$ext]",,1);
      $i = $i + 1;
   }
   #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 »

...I don't know whether it will keep trying or not...
...the thing is - it did the magic at the first, the second and the third attempts (files x, x-01, x02): it WORKS!!!
Thanks much, TheQwerty! Made my day!
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 »

Came up with something...
Why not emulating the 3-state pressing button to get the cyclic "rename with/without extension/send caret to the end of file name/loop" by doing something like this

Code: Select all

#172, 1; #172, 1; #172, 1 //File -> Rename
or

Code: Select all

#172, wait=1; #172, wait=1; #172, wait=1 //File -> Rename
?
Actual attempts failed... but would be possible, why not?
-should WORK, in fact! :?
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 »

For a final version (still lacking the user-defined alternate cyclic renaming mode, currently not implemented and no workaround I was able to provide):

EDIT: Fixed. Now it alternate states. Not perfect - it's not a universal solution as if it was provided by a function but allows for a little customization. Will require some editing on the last line to achieve the desired effect.

Code: Select all

//New Text File with Path and Custom Date in Rename Mode
"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");   
   Focus('L');
   Sel();
   $i = 0;
   while (GetInfo('CountSelected') == 0 and $i < 1000000000) {
      Sel("[$prefix$suffix$ext]",,1);
      $i = $i + 1;
   }
   sendkeys"{F2}"; wait 100; sendkeys"{F2}"; wait 100; sendkeys"{F2}"; wait 100; //File -> Rename
Last edited by SkyFrontier on 31 Aug 2010 02:50, edited 1 time in total.
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 »

Got it. 8)
Used two undocumented commands to get the cyclic emulation effect.

Replaced "#172; //File -> Rename" with

Code: Select all

sendkeys"{F2}"; wait 100; sendkeys"{F2}"; wait 100; sendkeys"{F2}"; wait 100;
Works a treat! :P
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 »

Each and every single day since 2007 I visit GiveawayOfTheDay (external link!) looking after commercial software available for free within a 24 hours window.
Now and then they offer a serial number that's valid for online versions and future versions, in some cases, allowing re-installation when needed.
Since it's wide open info you get right out of their installer, I believe they are aware that the user has the right to at least backup such keys, not infringing the concept at all (otherwise they could simply use another method they have for invisibly registering such software at user's machine).
I always wanted a way to easily tag, backup (I always store the info as a two-liner inside a document) and edit those things.
Now I can.

(Parts of the code by Serendipity. Thanks, man!)

Code: Select all

//New Text File with Path and Custom Date in Rename Mode
"Do Stuff"
   // Filename before the (possible) suffix.
   $prefix = 'GotDKey_' . 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.
   $textfooter="<crlf><crlf>===============<crlf><crlf>";
   $text="$textfooter <clipboard>";
   $err = WriteFile("<curpath>\$prefix$suffix$ext", "$text", 'n');
   End($err != 1, "Could not write file:<crlf>$prefix$suffix$ext");   
   Focus('L');
   Sel();
   $i = 0;
   while (GetInfo('CountSelected') == 0 and $i < 1000000000) {
      Sel("[$prefix$suffix$ext]",,1);
      $i = $i + 1;
   }
   open "<curitem>"
   //open "<curpath>\<curitem>" //ERROR
   //sendkeys"{F2}"; wait 100; sendkeys"{F2}"; wait 100; sendkeys"{F2}"; wait 100; //File -> Rename Mode
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 »

Unofficial Senkeys Documentation.
May help someone on similar workarounds...
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