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

rename file with random character

Post by swan_x »

i want change (rename) name on my file with random character without extension, example:
freddy.txt ---to--- sjdkfhr73teyebrg

i have try with rename special - RegExp Rename but i don't understand how to ...

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

Re: rename file with random character

Post by highend »

RegExp Rename but i don't understand how to
Because it's not possible without scripting
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: rename file with random character

Post by bdeshi »

:ninja: very old script. check before running.

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 ***/
  $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";
(updated, uses <get rs>, and a bugfix.)
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 »

ok many tanxs for your support!
anyway i did not think it was so difficult... many programs do this in an easy way... now i try! tanxs

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

Re: rename file with random character

Post by swan_x »

i have already one little easy and simple prog that does this, but i wanted to use XY!
and then rename special - RegExp Rename what is it for??
Last edited by swan_x on 18 Jan 2019 16:47, edited 1 time in total.

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 »

Oh, Sammay, while you posted that script I added a useful little random string generator to the app. :)

Code: Select all

   + SC get got a new named argument "rs" to return a random string.
      Syntax: get("rs", [length=8] [characters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"])
        length: Length (character count) of the returned string.
                Defaults to 8.
                You can also give a min and a max value separated by "-" for a random length, e.g. "8-12".
                There is an arbitrary maximum length of 32768, just to protect you from yourself.
        characters: Characters from which the returned string is built.
                Defaults to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".
        return: Random string.
      Examples:
        echo get("rs");
        echo get("rs", 8, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
        echo get("rs", "4-12", "abc");
        echo get("rs", 12, ". ");
      Of course, also the variable <get ...> supports it:
        echo <get rs>;
        echo <get rs 8 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789>;
        echo <get rs 4-12 abc>;
        echo <get rs 12 ". ">;
   >  Tip: Now you can use <get rs> in Batch Rename to rename a file to some random string.

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

Re: rename file with random character

Post by swan_x »

@ admin

oh yes! we find it in the next beta version??

Leito
Posts: 561
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: rename file with random character

Post by Leito »

swan_x wrote: 18 Jan 2019 16:45 and then rename special - RegExp Rename what is it for??
This command is to rename items by using a regular expression (using a pattern as a search term instead of a specific character/word). This has nothing to do with random characters. Check regular-expressions.info for more general info on regular expressions (or regex / regexp).

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: 18 Jan 2019 16:49 @ admin

oh yes! we find it in the next beta version??
Yes, in next beta this will do your job (the /e switch ensures that the extension is replaced as well):

Code: Select all

<get rs 16> /e
Attachments
XYRenameRandom.png
XYRenameRandom.png (3.99 KiB) Viewed 2091 times

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

Re: rename file with random character

Post by swan_x »

@ SammaySarkar

your script work very well, but if i have a list of files? how to change script to rename all files on selected list??

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

Re: rename file with random character

Post by highend »

The script already renames all selected files? oO
One of my scripts helped you out? Please donate via Paypal

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

Re: rename file with random character

Post by swan_x »

I do not understand your humor...
this script work only with one selected file, not work with a list of files...

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

Re: rename file with random character

Post by highend »

Really interesting. Oh no, not really...
2019-01-18_232337.png
2019-01-18_232337.png (11.34 KiB) Viewed 2065 times
One of my scripts helped you out? Please donate via Paypal

RalphM
Posts: 1932
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: rename file with random character

Post by RalphM »

While on this subject and out of curiosity, why would one want to strip identifying parts from a filename and replace them with senseless random characters, apart from obfuscation needs for screenshots and such which can already be achieved by using "obfuscate" in XY?
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

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: 18 Jan 2019 19:50 @ SammaySarkar
your script work very well, but if i have a list of files? how to change script to rename all files on selected list??
highend is not being funny :titter:, but I think what you're missing is that you need to select all the files that you want to rename. So you want to rename all files in the list? Then first select all of them and then run the script.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply