Page 1 of 3
rename file with random character
Posted: 18 Jan 2019 15:12
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 ...
Re: rename file with random character
Posted: 18 Jan 2019 15:28
by highend
RegExp Rename but i don't understand how to
Because it's not possible without scripting
Re: rename file with random character
Posted: 18 Jan 2019 15:38
by bdeshi

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.)
Re: rename file with random character
Posted: 18 Jan 2019 16:39
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
Re: rename file with random character
Posted: 18 Jan 2019 16:45
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??
Re: rename file with random character
Posted: 18 Jan 2019 16:46
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.
Re: rename file with random character
Posted: 18 Jan 2019 16:49
by swan_x
@ admin
oh yes! we find it in the next beta version??
Re: rename file with random character
Posted: 18 Jan 2019 16:51
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).
Re: rename file with random character
Posted: 18 Jan 2019 17:38
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):
Re: rename file with random character
Posted: 18 Jan 2019 19:50
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??
Re: rename file with random character
Posted: 18 Jan 2019 22:52
by highend
The script already renames all selected files? oO
Re: rename file with random character
Posted: 18 Jan 2019 23:14
by swan_x
I do not understand your humor...
this script work only with one selected file, not work with a list of files...
Re: rename file with random character
Posted: 18 Jan 2019 23:24
by highend
Really interesting. Oh no, not really...
2019-01-18_232337.png
Re: rename file with random character
Posted: 19 Jan 2019 02:01
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?
Re: rename file with random character
Posted: 19 Jan 2019 05:27
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

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