rename file with random character

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

don't work. I'm not stupid. I tried, obviously, before posting.
if i select a list of files, and run the script, only the first name in the list is changed...

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

Re: rename file with random character

Post by bdeshi »

Well that's impossible. How are you running the script?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

i have saved your script on new command from “manage command - script”.
then i select my list of files, run script, but only the first file change name...

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

Re: rename file with random character

Post by bdeshi »

Hang on. You select a list of files, meaning you select ONE file which CONTAINS a list of files?

Then try this version of the script, now updated to use get('rs'):

Code: Select all

"RenameRandom from Filelist : renamerandom_filelist"
  // 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   = replacelist($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
  $sel    = formatlist(replace(readfile(<curitem>), <crlf>, '|'), 'e');        // 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
    wait 1;
    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";
Although note that there might be a little issue with renames: viewtopic.php?f=2&t=19956
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

@ admin
i've try your latest beta and work very fine with batch rename:
<get rs 8 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789>

but how to remove estension on the new file name??

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

@ SammaySarkar

i've try your latest script, but after select my all files, then run your script from "Script - run script" i have one error... see attach
Attachments
Appunti01.jpg
Appunti01.jpg (36.24 KiB) Viewed 1542 times

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

on continue script i have a new error
Attachments
Appunti01s.jpg
Appunti01s.jpg (36.3 KiB) Viewed 1542 times

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

Re: rename file with random character

Post by admin »

swan_x wrote: 19 Jan 2019 14:21 @ admin
i've try your latest beta and work very fine with batch rename:
<get rs 8 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789>

but how to remove estension on the new file name??
Look at my post again... viewtopic.php?p=166223#p166223

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

@ admin
oh yeeeesss!! now really work fine! tnxs

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

Re: rename file with random character

Post by admin »

Remains the question: Why are you doing this randomizing of filenames? :?

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

for hide some files.
and more, i want rename some files before move to recycle, so as not to be recovered later with professional prog, ex Recoverit or EaseUS Data Recovery Wizard.

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

and why, see my post above, i have 2 error on script of SammaySarkar??

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

Re: rename file with random character

Post by bdeshi »

swan_x wrote: 19 Jan 2019 15:51 and why, see my post above, i have 2 error on script of SammaySarkar??
Because you still need to select a file containing the list of files to rename, duh.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

swan_x
Posts: 321
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x »

@ sammay
<you still need to select a file containing the list of files to rename>
i don't want this. i don't have a file containing the list of files to rename... i have some files on my folder and i want rename it...

@ admin
if i want assign shortcut (ex ALT+M) to batchrename funcion:
<get rs 8 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789> /e
how to this??

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

Re: rename file with random character

Post by admin »

swan_x wrote: 19 Jan 2019 18:19 if i want assign shortcut (ex ALT+M) to batchrename funcion:
<get rs 8 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789> /e
how to this??
Check out User / Rename ... (via User | Manage Commands...)

Post Reply