rename file with random character

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

Re: rename file with random character

Post by swan_x » 19 Jan 2019 09:37

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...

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

Re: rename file with random character

Post by SammaySarkar » 19 Jan 2019 10:52

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

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

Re: rename file with random character

Post by swan_x » 19 Jan 2019 11:43

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...

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

Re: rename file with random character

Post by SammaySarkar » 19 Jan 2019 11:56

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: 216
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x » 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??

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

Re: rename file with random character

Post by swan_x » 19 Jan 2019 14:24

@ 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 387 times

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

Re: rename file with random character

Post by swan_x » 19 Jan 2019 14:26

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

admin
Site Admin
Posts: 47947
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: rename file with random character

Post by admin » 19 Jan 2019 14:30

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: 216
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x » 19 Jan 2019 14:46

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

admin
Site Admin
Posts: 47947
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: rename file with random character

Post by admin » 19 Jan 2019 15:43

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

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

Re: rename file with random character

Post by swan_x » 19 Jan 2019 15:49

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: 216
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x » 19 Jan 2019 15:51

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

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

Re: rename file with random character

Post by SammaySarkar » 19 Jan 2019 17:17

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: 216
Joined: 08 Oct 2009 12:27

Re: rename file with random character

Post by swan_x » 19 Jan 2019 18:19

@ 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: 47947
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: rename file with random character

Post by admin » 19 Jan 2019 19:10

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