Page 1 of 1

Rename files and folders to random names

Posted: 16 Jul 2012 16:25
by david.lynch
Hello everyone! Image

I'm looking for a way to rename all files and folders from a given folder (%1), including subfolders. The purpose is to help obfuscate what they are. Names are really unwanted in this scenario.

It should work even on +r, +h , +s files and folders.

These names should look like nothing - or for instance like a damaged file system, with a wide range of characters.

Does exist a script like this? is this possible?

Image

Re: Rename files and folders to random names

Posted: 16 Jul 2012 18:29
by TB99

Code: Select all

C:\test>type  randomname.bat
@echo off
cd c:\test\
dir /b ab*.txt > testdata.txt
type testdata.txt

for /f %%i in ( testdata.txt) do (

echo copy %%i %%i%random%.txt
echo ren %%i %%i%random%.txt

)
C:\test> randomname.bat
abc.txt
abc2.txt
copy abc.txt abc.txt15611.txt
ren abc.txt abc.txt23205.txt
copy abc2.txt abc2.txt15611.txt
ren abc2.txt abc2.txt23205.txt

C:\test>

Re: Rename files and folders to random names

Posted: 16 Jul 2012 21:08
by Liviu
@david, you may want to elaborate on that "scenario". The requirements sound quite odd, and you might get better help if you described the context a bit more.

@bill, you don't need a temp file, the code skips s/h files, ignores directories, doesn't recurse into subdirectories, %random% is evaluated before the "for" loop runs so it's not that random at all, and there is no safeguard against clashing (re)names. Other than that, it's a starting point, and you've got the board 'code' tags right at least ;-)

Liviu

Re: Rename files and folders to random names

Posted: 16 Jul 2012 21:14
by Ocalabob
Greetings David.Lynch,

The purpose is to help obfuscate what they are. Names are really unwanted in this scenario.


Do you mean the file name only or the file name and extension?

If you don't mind another question, I'm curious as to why would you want to do this as this may well be irreversible.

Best wishes, and I look forward to your reply!

Re: Rename files and folders to random names

Posted: 17 Jul 2012 02:35
by foxidrive
david.lynch wrote:Hello everyone! Image

I'm looking for a way to rename all files and folders from a given folder (%1), including subfolders. The purpose is to help obfuscate what they are. Names are really unwanted in this scenario.

It should work even on +r, +h , +s files and folders.

These names should look like nothing - or for instance like a damaged file system, with a wide range of characters.

Does exist a script like this? is this possible?


It's possible to build random filenames from a character set - but it would be terribly destructive and could be the basis for malware.

Another way to destroy a file system would be to exchange the filenames randomly amongst all the files.

Re: Rename files and folders to random names

Posted: 17 Jul 2012 06:08
by Squashman
foxidrive wrote:
david.lynch wrote:Hello everyone! Image

I'm looking for a way to rename all files and folders from a given folder (%1), including subfolders. The purpose is to help obfuscate what they are. Names are really unwanted in this scenario.

It should work even on +r, +h , +s files and folders.

These names should look like nothing - or for instance like a damaged file system, with a wide range of characters.

Does exist a script like this? is this possible?


It's possible to build random filenames from a character set - but it would be terribly destructive and could be the basis for malware.

Another way to destroy a file system would be to exchange the filenames randomly amongst all the files.

On most forums I belong to, they would consider this destructive and lock the thread.

Re: Rename files and folders to random names

Posted: 17 Jul 2012 06:17
by Squashman
Liviu wrote:@bill, you don't need a temp file, the code skips s/h files, ignores directories, doesn't recurse into subdirectories, %random% is evaluated before the "for" loop runs so it's not that random at all, and there is no safeguard against clashing (re)names. Other than that, it's a starting point, and you've got the board 'code' tags right at least ;-)

Liviu

And it doesn't remove the original file extension and you would think that you would not want to use any portion of the original file name if the OP wants to obfuscate what the original file name is or what the the file type was. But obfuscating the file extension is like doing security through obscurity. There are utilities that you can use to tell you what type of file a file is.

Re: Rename files and folders to random names

Posted: 17 Jul 2012 06:26
by foxidrive
Squashman wrote:
foxidrive wrote:It's possible to build random filenames from a character set - but it would be terribly destructive and could be the basis for malware.

Another way to destroy a file system would be to exchange the filenames randomly amongst all the files.

On most forums I belong to, they would consider this destructive and lock the thread.


I'm not surprised. I wouldn't write something like that which could be used by a disgruntled employee on his last day at the office.

Re: Rename files and folders to random names

Posted: 17 Jul 2012 10:22
by david.lynch
Sorry, it seems that I'm a little late for replies here :)

The long history:

The purpose is really not bad, as file contents remains intact. This would be a more elaborated version of what we see on this How-To Geek article:

http://www.howtogeek.com/?post_type=post&p=57661

@Ocalabob: filenames and extensions.

This will be used for a initial preparation of a custom database, the choice of a internal developer. The names *need* to look completely strange, and then the developer will identify them by content on his application and they will not be renamed anymore.

Since there are a lot of files and subfolders, indexes and tables, a batch would do the job nicely.

I know that this is a strange question, but that's how things are sometimes Image

Image

Re: Rename files and folders to random names

Posted: 17 Jul 2012 12:52
by Liviu
@bill, I'do it with a plain for loop inside a for/d loop called recursively. There are switches to deal with r/s/h files. I'd use !random! instead of %random%, or better still uuidgen.exe from the sdk, plus check for existence of the target name in advance and avoid overwriting.

@david, since your internal developer must already have code to recurse into subdirectories and iterate over each set of files, it would only take a tiny extra function for him to handle the rename part.

Regarding the "stupid geek tricks" link, it's always a good idea to take such random sightings with a grain of caution. Their claim that the operation is "undoable" is, to put it mildly, exaggerated. Since the "undo" file is plain text, any original filenames using characters outside the current codepage are lost. Also, the way it's written, even some plain ASCII characters like ^%! can trip the code.

Re: Rename files and folders to random names

Posted: 17 Jul 2012 14:31
by david.lynch
Liviu wrote:@david, since your internal developer must already have code to recurse into subdirectories and iterate over each set of files, it would only take a tiny extra function for him to handle the rename part.


You're right. When he stumbled into this I've told him that some tool could already exist and do it faster and surprise: we found nothing. So I've asked here.

But since then, would be faster to him write it himself Image

Thanks anyway! Image