rename file with random character
rename file with random character
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 ...
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
Because it's not possible without scriptingRegExp Rename but i don't understand how to
One of my scripts helped you out? Please donate via Paypal
Re: rename file with random character
very old script. check before running.
(updated, uses <get rs>, and a bugfix.)
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";
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: rename file with random character
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
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
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??
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.
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: rename file with random character
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.
FAQ | XY News RSS | XY Twitter
Re: rename file with random character
@ admin
oh yes! we find it in the next beta version??
oh yes! we find it in the next beta version??
Re: rename file with random character
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).
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: rename file with random character
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 (3.99 KiB) Viewed 2091 times
FAQ | XY News RSS | XY Twitter
Re: rename file with random character
@ 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??
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
The script already renames all selected files? oO
One of my scripts helped you out? Please donate via Paypal
Re: rename file with random character
I do not understand your humor...
this script work only with one selected file, not work with a list of files...
this script work only with one selected file, not work with a list of files...
Re: rename file with random character
Really interesting. Oh no, not really...
One of my scripts helped you out? Please donate via Paypal
Re: rename file with random character
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%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
Re: rename file with random character
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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]