View unanswered posts | View active topics It is currently 23 Apr 2014 07:13



Post new topic Reply to topic  [ 11 posts ] 
Rename files and folders to random names 
Author Message

Joined: 08 Jul 2012 21:00
Posts: 13
Post Rename files and folders to random names
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


16 Jul 2012 16:25
Profile

Joined: 16 Jul 2012 15:36
Posts: 1
Post Re: Rename files and folders to random names
Code:
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>


16 Jul 2012 18:29
Profile
Expert

Joined: 13 Jan 2012 21:24
Posts: 400
Post Re: Rename files and folders to random names
@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
Profile

Joined: 24 Dec 2010 12:16
Posts: 79
Location: Micanopy Florida
Post 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
Profile

Joined: 10 Feb 2012 02:20
Posts: 3672
Post Re: Rename files and folders to random names
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.


17 Jul 2012 02:35
Profile

Joined: 23 Dec 2011 13:59
Posts: 1547
Post Re: Rename files and folders to random names
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.


17 Jul 2012 06:08
Profile

Joined: 23 Dec 2011 13:59
Posts: 1547
Post 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
Profile

Joined: 10 Feb 2012 02:20
Posts: 3672
Post 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
Profile

Joined: 08 Jul 2012 21:00
Posts: 13
Post 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:

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


17 Jul 2012 10:22
Profile
Expert

Joined: 13 Jan 2012 21:24
Posts: 400
Post 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
Profile

Joined: 08 Jul 2012 21:00
Posts: 13
Post 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.

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

Thanks anyway! Image


17 Jul 2012 14:31
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 


Who is online

Users browsing this forum: Bing [Bot], penpen, siberia-man and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.