random renamer (dos/windows)

Everything todo with programming goes HERE.
Post Reply
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

random renamer (dos/windows)

Post by iceman »

I wrote this small rename app (4.6k) that renames all files in a folder with random file names

it will change the filename only and leave the file extension intact

just extract the random.exe file into a folder full of files you wish to rename and then click on the exe to rename everything in that folder (including random.exe ! LOL)

---------------------------------------------------------------------------------

NOTE: old link removed see end of post for new link and source code
Last edited by iceman on Sat Aug 13, 2005 9:06 pm, edited 1 time in total.
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
Tank Program
Forum & Project Admin, PhD
Posts: 6711
Joined: Thu Dec 18, 2003 7:03 pm

Post by Tank Program »

Another crazy iceman program... I'll have to use this on someone... :twisted:
Image
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

How about randomly picking entries from a dictionary? :)
ˌɑrməˈɡɛˌtrɑn
User avatar
dlh
Formerly That OS X Guy
Posts: 2035
Joined: Fri Jan 02, 2004 12:05 am
Contact:

Post by dlh »

Jonathan wrote:How about randomly picking entries from a dictionary? :)
/usr/share/dict/words exists on Windows?
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

Tank Program wrote:Another crazy iceman program... I'll have to use this on someone... :twisted:
yeah run it in c:\windows :lol: :twisted:


seriously tank thats NOT the reason I wrote it.

when I transfer images from my cell phone they all have names like image001 image002 etc etc and I was getting sick of images getting overwritten by new ones and the fact that I had to rename all the files to stop this happening, this is why I wrote the app.

but do with it what you like :twisted:
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

iceman wrote:when I transfer images from my cell phone they all have names like image001 image002 etc etc and I was getting sick of images getting overwritten by new ones and the fact that I had to rename all the files to stop this happening, this is why I wrote the app.
I'd rather timestamp them.
ˌɑrməˈɡɛˌtrɑn
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

Jonathan wrote:
iceman wrote:when I transfer images from my cell phone they all have names like image001 image002 etc etc and I was getting sick of images getting overwritten by new ones and the fact that I had to rename all the files to stop this happening, this is why I wrote the app.
I'd rather timestamp them.
yeah thats easy to do to but I like the randomness (you all probably know that I have a thing about random numbers :lol:)
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

But what if you get a collision? Or if you want to find a specific photo?
ˌɑrməˈɡɛˌtrɑn
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

Jonathan wrote:But what if you get a collision? Or if you want to find a specific photo?
havent had a collision yet but if it happens there will just be a 'file already exists' message (i hope lol) i'll test this now using single character file names which should increase the chance of a collision

I use thumbnail view on the folder containing the photos so its not a problem picking out a specific pic if needed
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

lol its worse than I expected , collisions give the following message
Runtime error 005 at 0000:00DB! :lol:

I love that message :twisted:

will update the file and source in a few moments
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
Tank Program
Forum & Project Admin, PhD
Posts: 6711
Joined: Thu Dec 18, 2003 7:03 pm

Post by Tank Program »

iceman wrote:seriously tank thats NOT the reason I wrote it.
But you could have such fun with it...
Image
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

ok fixed the rename collision (rare but can happen)

new download here

Code: Select all

http://rapidshare.de/files/3948569/random.rar.html
new source code

Code: Select all

program random_renamer;			{ random renamer, iceman 2005 }



uses crt, dos;							{ include dos and crt librarys }

var
	old, new : string;				{ storage for old and new file name }

	dirinfo : SearchRec;			{ storege for the files names (dir *.*) }

	found : PathStr;					{ dupicate file found }

	ren : file;								{ file to rename }

	ind : integer;						{ character index }

	position : byte;					{ position of '.' in file name }


begin

	randomize;

														{ get list of file names in directory }
	findfirst('*.*', archive, dirinfo);

	while DosError = 0 do			{ while there are still files in the dir }
	begin

		old := dirinfo.name;		{ get original file name }

														{ get position of '.' }
		position := pos('.', old);

		if (position = 0)				{ if no '.' then set position to length of name }
			then position := length(old) + 1;

		new := old;							{ copy old file name + extension to new }


		repeat									{ create new random file name }

		for ind := 1 to position - 1 do
			new[ind] := chr(random(26)+65);

														{ check if new name already exists }
		found := FSearch(new, GetEnv('PATH'));

		until (found = '');			{ repeat until new name not found }

		assign(ren, old);	 			{ select old file name }

		rename(ren, new);				{ and rename to new random file name }

		writeln(old, ' ', new);	{ display results }

		FindNext(DirInfo);			{ go to next file }

	end;											{ loop back }

end.
same but without comments

Code: Select all

program random_renamer;			{ random renamer, iceman 2005 }



uses crt, dos;

var
	old, new : string;

	dirinfo : SearchRec;

	found : PathStr;

	ren : file;

	ind : integer;

	position : byte;


begin

	randomize;

	findfirst('*.*', archive, dirinfo);

	while DosError = 0 do
	begin

		old := dirinfo.name;

		position := pos('.', old);

		if (position = 0)
			then position := length(old) + 1;

		new := old;

		repeat

		for ind := 1 to position - 1 do
			new[ind] := chr(random(26)+65);

		found := FSearch(new, GetEnv('PATH'));

		until (found = '');

		assign(ren, old);
		rename(ren, new);

		writeln(old, ' ', new);

		FindNext(DirInfo);

	end;

end.
Last edited by iceman on Sat Aug 13, 2005 9:15 pm, edited 1 time in total.
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

now comes a new problem !

if you fill a folder with 208,827,064,577 files you will cause an infinite loop as every possible random name will be used and the program will not be able to create another unique name

I would like someone to test this for me :twisted:
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
Tank Program
Forum & Project Admin, PhD
Posts: 6711
Joined: Thu Dec 18, 2003 7:03 pm

Post by Tank Program »

iceman wrote:208,827,064,577
If your average cluster size is 4KB, and you fill the file below that, that will take up just a little below 778GB! I stronly suggest no one try this!
Image
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

Tank Program wrote:
iceman wrote:208,827,064,577
If your average cluster size is 4KB, and you fill the file below that, that will take up just a little below 778GB! I stronly suggest no one try this!
go on tank, i'm sure you have the drive space ;)

---------------------------

ok not a real problem then :D
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
Post Reply