@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

16 Jul 2012 21:08

Ocalabob

Joined: 24 Dec 2010 12:16Posts: 79Location: Micanopy Florida

Re: Rename files and folders to random names

Greetings David.Lynch,

Quote:

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!

16 Jul 2012 21:14

foxidrive

Joined: 10 Feb 2012 02:20Posts: 4696

Re: Rename files and folders to random names

david.lynch wrote:

Hello everyone!

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.

17 Jul 2012 02:35

Squashman

Joined: 23 Dec 2011 13:59Posts: 2388

Re: Rename files and folders to random names

foxidrive wrote:

david.lynch wrote:

Hello everyone!

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.

17 Jul 2012 06:08

Squashman

Joined: 23 Dec 2011 13:59Posts: 2388

Re: Rename files and folders to random names

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.

17 Jul 2012 06:17

foxidrive

Joined: 10 Feb 2012 02:20Posts: 4696

Re: Rename files and folders to random names

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.

17 Jul 2012 06:26

david.lynch

Joined: 08 Jul 2012 21:00Posts: 13

Re: Rename files and folders to random names

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:

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

17 Jul 2012 10:22

Liviu

Expert

Joined: 13 Jan 2012 21:24Posts: 456

Re: Rename files and folders to random names

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

17 Jul 2012 12:52

david.lynch

Joined: 08 Jul 2012 21:00Posts: 13

Re: Rename files and folders to random names

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.