[NotABug] curious problem with scripted rapid renames

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

[NotABug] curious problem with scripted rapid renames

Post by bdeshi »

Hey Don. This script is supposed to rename all selected files to completely random names.
But sometimes I see bits of the original names remaining inside the randomly generated strings.
Can you please check? run this script on, say, 25-30 files. If everything seems okay, kindly rerun two or three more times.

Code: Select all

"RenameRandom : renamerandom"
  // Renames current selected items to random names.
  /*** user-configurable options ***/
  $report = 1;   /* whether to generate a report of renames; 1 or 0 */
  $maxLen = 16;  /* max length of name; 0 < $maxLen < 256 */
  $minLen =  8;  /* min length of name; 0 < $minLen <= $maxLen */
  $pool   = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=+_'@$%&^~*#[](),.";
  // $pool = character pool for generating random names
  /*** end of user-configurable options ***/
  setting 'BackgroundFileOps', 0;
  $pool   = replace($pool, '\/:*?"<>|');                                       // remove disallowed characters
  $len    = gettoken($pool, 'count', ':');                                     // length of character pool
  $maxLen = ($maxLen > 255)     ?     255 : $maxLen ;                          // sanitize max length
  $minLen = ($minLen < 1)       ?       1 : $minLen ;                          // sanitize min length
  $maxLen = ($maxLen < $minLen) ? $minLen : $maxLen ;                          // sanitize min-max length range
  if $report { $report = ''; } else { unset $report; }                         // init reporting
  $sel    = get("SelectedItemsPathNames", '|');                                // items to rename, current selection
  $maxNameLen = 0;
  foreach ($item, $sel) {                                                      // get length of longest itemname in $sel
    $itemNameLen = strlen(gpc($item, 'file'));
    $lastMaxLen =($itemNameLen > $lastMaxLen) ? $itemNameLen : $lastMaxLen;
    $maxNameLen = $lastMaxLen;
  }
  foreach ($item, $sel) {
    $randName = gpc($item, 'file');
    while exists(gpc($item, 'path') . '\' . $randName) {                       // generate a unique random name
      $randLen  = rand($minLen, $maxLen);                                      // random name length for current loop item
      $randName = get('rs', $randLen, $pool);                                  // generate a random name
    }
    $randName = renameitem($randName, $item, 3);                               // perform the rename
    if isset($report) {                                                        // generate report
      $oldName = gpc($item, 'file');
      $report = $report . $oldName .
                strrepeat(' ', $maxNameLen-strlen($oldName)) . " -> " . 
                $randName . <crlf>;
    }
  }
  if isset($report) { text $report; }                                          // display report if available
  status "RenameRandom: finished";
Here are some random results.

BetterFileSelector.xys   -> D:\tools\XYplorer\xydata\Scripts\r%%MGubp(28A+3C_
BitnessDetector.xys      -> D:\tools\XYplorer\xydata\Scripts\A_SHLT)BK27))h
folder-pane-preview.xys  -> D:\tools\XYplorer\xydata\Scripts\csu3UC##N(r~qkb
pattern-sync-select.xys  -> D:\tools\XYplorer\xydata\Scripts\XNMgwZ~Tpattern-sync-select88YePf
pfa_xys.xys              -> D:\tools\XYplorer\xydata\Scripts\du,mrwUY
PreviewFolder.xys        -> D:\tools\XYplorer\xydata\Scripts\V#,z7L7p[S
properties.ini           -> D:\tools\XYplorer\xydata\Scripts\yPyl7QZxcX1Xn
properties.xys           -> D:\tools\XYplorer\xydata\Scripts\qH7'0CE@c
RunasAdminToggle.xys     -> D:\tools\XYplorer\xydata\Scripts\QvDQB[p6#
Selections.xys           -> D:\tools\XYplorer\xydata\Scripts\K96eOwAcRXzAe.R8
sessionmanager.ini       -> D:\tools\XYplorer\xydata\Scripts\jR,4@tPEt(=S#QU
SessionManager.xys       -> D:\tools\XYplorer\xydata\Scripts\I=ZPiASBeE(5Ic%0
subtagger.xys            -> D:\tools\XYplorer\xydata\Scripts\6yg0^ul#]9+6PzVp
test.xys                 -> D:\tools\XYplorer\xydata\Scripts\Q_yL(8)wCAuZ#~~
ThumbnailMaintenance.xys -> D:\tools\XYplorer\xydata\Scripts\gAj$wBVrlf3zThumbnailMaintenance~g
TimestampSerializer.xys  -> D:\tools\XYplorer\xydata\Scripts\bSHjcFFTimestampSerializer=d,76o
tmp.xys                  -> D:\tools\XYplorer\xydata\Scripts\+XW9SCXv3qQAzjTj
XYCollector.xys          -> D:\tools\XYplorer\xydata\Scripts\F~)4T]CnScm8
xypcre.exe               -> D:\tools\XYplorer\xydata\Scripts\msNmeiEv

BetterFileSelector.xys   -> D:\tools\XYplorer\xydata\Scripts\&TDw5xYDiGZ
BitnessDetector.xys      -> D:\tools\XYplorer\xydata\Scripts\HY=%lu6'uqze
folder-pane-preview.xys  -> D:\tools\XYplorer\xydata\Scripts\q&(WEVuUat]$Ol
pattern-sync-select.xys  -> D:\tools\XYplorer\xydata\Scripts\G2E0pattern-sync-selectzoA@^5
pfa_xys.xys              -> D:\tools\XYplorer\xydata\Scripts\5T.49Pg=3H
PreviewFolder.xys        -> D:\tools\XYplorer\xydata\Scripts\h+oqVyb)6&2o$
properties.ini           -> D:\tools\XYplorer\xydata\Scripts\()$YNadz8IB
properties.xys           -> D:\tools\XYplorer\xydata\Scripts\fSqH^j3X1
RunasAdminToggle.xys     -> D:\tools\XYplorer\xydata\Scripts\~.51[K&%Ue40X
Selections.xys           -> D:\tools\XYplorer\xydata\Scripts\5_QuZntc
sessionmanager.ini       -> D:\tools\XYplorer\xydata\Scripts\HMYG_c[8lkY],WP
SessionManager.xys       -> D:\tools\XYplorer\xydata\Scripts\qDng=g^S-o7%T
subtagger.xys            -> D:\tools\XYplorer\xydata\Scripts\bmJr^hB5qf_w8&Cd
test.xys                 -> D:\tools\XYplorer\xydata\Scripts\L^=RfR3NP0yf
ThumbnailMaintenance.xys -> D:\tools\XYplorer\xydata\Scripts\d6y~QdoThumbnailMaintenance4hUACC
TimestampSerializer.xys  -> D:\tools\XYplorer\xydata\Scripts\Uo9bZsh-GrVsN
tmp.xys                  -> D:\tools\XYplorer\xydata\Scripts\PWl$Z35@+cJW@nN
XYCollector.xys          -> D:\tools\XYplorer\xydata\Scripts\6woG#)OXiB
xypcre.exe               -> D:\tools\XYplorer\xydata\Scripts\f(DzVDJF-'paPbVh

BetterFileSelector.xys   -> D:\tools\XYplorer\xydata\Scripts\-vU~kg4l']N'$
BitnessDetector.xys      -> D:\tools\XYplorer\xydata\Scripts\UZEUnSBitnessDetectorLz#ZeL.j9
folder-pane-preview.xys  -> D:\tools\XYplorer\xydata\Scripts\Xlvqn&k2=
pattern-sync-select.xys  -> D:\tools\XYplorer\xydata\Scripts\X1-Y5(C0Qf
pfa_xys.xys              -> D:\tools\XYplorer\xydata\Scripts\I$K1&]hmF3t#8
PreviewFolder.xys        -> D:\tools\XYplorer\xydata\Scripts\F.rYX8)ZcE4'UXR
properties.ini           -> D:\tools\XYplorer\xydata\Scripts\e2o6BJwP(#hQ+,D
properties.xys           -> D:\tools\XYplorer\xydata\Scripts\ovL3fI-1YQDJ)
RunasAdminToggle.xys     -> D:\tools\XYplorer\xydata\Scripts\@tm0MvOZ2HepRJF
Selections.xys           -> D:\tools\XYplorer\xydata\Scripts\-uWSelections&NTtJ
sessionmanager.ini       -> D:\tools\XYplorer\xydata\Scripts\Nm~40FyAGIU
SessionManager.xys       -> D:\tools\XYplorer\xydata\Scripts\L1_yJ^)VS(9I2
subtagger.xys            -> D:\tools\XYplorer\xydata\Scripts\7oZV8D0kT9m57-'
test.xys                 -> D:\tools\XYplorer\xydata\Scripts\-]9[N$k~5j+4h+K^
ThumbnailMaintenance.xys -> D:\tools\XYplorer\xydata\Scripts\#+&NBkG2+c
TimestampSerializer.xys  -> D:\tools\XYplorer\xydata\Scripts\#sKeBG[$M
tmp.xys                  -> D:\tools\XYplorer\xydata\Scripts\mkao2_Ta]d]&XP
XYCollector.xys          -> D:\tools\XYplorer\xydata\Scripts\()@N]+wYCz5
xypcre.exe               -> D:\tools\XYplorer\xydata\Scripts\kO_TNTOm(53(5
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: curious problem with scripted rapid renames

Post by highend »

What happens if you use an artificial wait before the

Code: Select all

$randName = renameitem($randName, $item, 3); 
line, e.g. 20ms?
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: curious problem with scripted rapid renames

Post by bdeshi »

Same. I tried upto wait 100; before, after.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: curious problem with scripted rapid renames

Post by admin »

Indeed curious. I'll check that...

In the meantime I'm curious as well: What is the purpose of this script? As shown in viewtopic.php?p=166223#p166223 this can be achieved without scripting now simply via Batch Rename. Anything I did not understand? :eh:

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: curious problem with scripted rapid renames

Post by bdeshi »

because i had already written it! :whistle:
besides, if i'm being pedantic, the chance of two items in batch rename getting the same random name is not zero, so i rename one by one. [ed.]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: curious problem with scripted rapid renames

Post by admin »

Solution: you are using * in your character list. See Help on renameitem():

newname The new name (will be used as base and/or extension, depending on flags).
    The newname argument supports the following placeholders:
    * = original base
    ? = original extension 


:)

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: curious problem with scripted rapid renames

Post by bdeshi »

Aah!
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: curious problem with scripted rapid renames

Post by bdeshi »

Hm, no, that's not it. I'm removing invalid chars from the character pool.
[code] $pool = replace($pool, '\/:*?"<>|'); // remove disallowed characters[/code]

...
Ok, you're right.
Silly me. That was supposed to be a replacelist. :oops:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply