DosTips.com

A Forum all about DOS Batch
It is currently 25 Jul 2016 14:02

All times are UTC-06:00




Post new topic  Reply to topic  [ 11 posts ] 
Author Message
PostPosted: 16 Jul 2012 16:25 
Offline

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


Top
   
PostPosted: 16 Jul 2012 18:29 
Offline

Joined: 16 Jul 2012 15:36
Posts: 1
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>


Top
   
PostPosted: 16 Jul 2012 21:08 
Offline
Expert

Joined: 13 Jan 2012 21:24
Posts: 469
@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


Top
   
PostPosted: 16 Jul 2012 21:14 
Offline

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


Top
   
PostPosted: 17 Jul 2012 02:35 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5789
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.


Top
   
PostPosted: 17 Jul 2012 06:08 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3140
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.


Top
   
PostPosted: 17 Jul 2012 06:17 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3140
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.


Top
   
PostPosted: 17 Jul 2012 06:26 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5789
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.


Top
   
PostPosted: 17 Jul 2012 10:22 
Offline

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


Top
   
PostPosted: 17 Jul 2012 12:52 
Offline
Expert

Joined: 13 Jan 2012 21:24
Posts: 469
@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.


Top
   
PostPosted: 17 Jul 2012 14:31 
Offline

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 11 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], npocmaka_, Yahoo [Bot] and 11 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® Forum Software © phpBB Limited